Skip to content

Commit

Permalink
Merge pull request #1024 from tock/struct-lifetimes
Browse files Browse the repository at this point in the history
Use several nice newish Rust features
  • Loading branch information
ppannuto committed Jun 29, 2018
2 parents c879d5f + 6053068 commit 5b410e3
Show file tree
Hide file tree
Showing 85 changed files with 352 additions and 350 deletions.
4 changes: 2 additions & 2 deletions boards/imix/src/icmp_lowpan_test.rs
Expand Up @@ -65,7 +65,7 @@ pub static mut RF233_BUF: [u8; radio::MAX_BUF_SIZE] = [0 as u8; radio::MAX_BUF_S

//Use a global variable option, initialize as None, then actually initialize in initialize all

pub struct LowpanICMPTest<'a, A: time::Alarm + 'a> {
pub struct LowpanICMPTest<'a, A: time::Alarm> {
alarm: A,
//sixlowpan_tx: TxState<'a>,
//radio: &'a Mac<'a>,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'a, A: time::Alarm> capsules::net::icmpv6::icmpv6_send::ICMP6SendClient
}
}

impl<'a, A: time::Alarm + 'a> LowpanICMPTest<'a, A> {
impl<A: time::Alarm> LowpanICMPTest<'a, A> {
pub fn new(
//sixlowpan_tx: TxState<'a>,
//radio: &'a Mac<'a>,
Expand Down
2 changes: 1 addition & 1 deletion boards/imix/src/ipv6_lowpan_test.rs
Expand Up @@ -134,7 +134,7 @@ static mut UDP_DGRAM: [u8; PAYLOAD_LEN - UDP_HDR_SIZE] = [0; PAYLOAD_LEN - UDP_H
static mut IP6_DG_OPT: Option<IP6Packet> = None;
//END changes

pub struct LowpanTest<'a, A: time::Alarm + 'a> {
pub struct LowpanTest<'a, A: time::Alarm> {
alarm: A,
sixlowpan_tx: TxState<'a>,
radio: &'a MacDevice<'a>,
Expand Down
2 changes: 2 additions & 0 deletions boards/imix/src/main.rs
Expand Up @@ -5,6 +5,8 @@

#![no_std]
#![no_main]
#![feature(in_band_lifetimes)]
#![feature(infer_outlives_requirements)]
#![feature(panic_implementation)]
#![deny(missing_docs)]

Expand Down
6 changes: 3 additions & 3 deletions boards/imix/src/sixlowpan_dummy.rs
Expand Up @@ -83,13 +83,13 @@ enum DAC {
pub const TEST_DELAY_MS: u32 = 1000;
pub const TEST_LOOP: bool = false;

pub struct LowpanTest<'a, R: radio::Radio + 'a, A: time::Alarm + 'a> {
pub struct LowpanTest<'a, R: radio::Radio , A: time::Alarm > {
radio: &'a R,
alarm: &'a A,
test_counter: Cell<usize>,
}

impl<'a, R: radio::Radio + 'a, A: time::Alarm + 'a>
impl<'a, R: radio::Radio , A: time::Alarm >
LowpanTest<'a, R, A> {
pub fn new(radio: &'a R, alarm: &'a A) -> LowpanTest<'a, R, A> {
LowpanTest {
Expand Down Expand Up @@ -167,7 +167,7 @@ LowpanTest<'a, R, A> {
}
}

impl<'a, R: radio::Radio + 'a, A: time::Alarm + 'a>
impl<'a, R: radio::Radio , A: time::Alarm >
time::Client for LowpanTest<'a, R, A> {
fn fired(&self) {
self.run_test_and_increment();
Expand Down
4 changes: 2 additions & 2 deletions boards/imix/src/udp_lowpan_test.rs
Expand Up @@ -64,7 +64,7 @@ pub static mut RF233_BUF: [u8; radio::MAX_BUF_SIZE] = [0 as u8; radio::MAX_BUF_S

//Use a global variable option, initialize as None, then actually initialize in initialize all

pub struct LowpanTest<'a, A: time::Alarm + 'a> {
pub struct LowpanTest<'a, A: time::Alarm> {
alarm: A,
//sixlowpan_tx: TxState<'a>,
//radio: &'a Mac<'a>,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<'a, A: time::Alarm> capsules::net::udp::udp_send::UDPSendClient for LowpanT
}
}

impl<'a, A: time::Alarm + 'a> LowpanTest<'a, A> {
impl<'a, A: time::Alarm> LowpanTest<'a, A> {
pub fn new(
//sixlowpan_tx: TxState<'a>,
//radio: &'a Mac<'a>,
Expand Down
14 changes: 7 additions & 7 deletions capsules/examples/traitobj_list.rs
Expand Up @@ -20,18 +20,18 @@ use kernel::common::list::*;

pub trait Funky<'a> {
fn name(&self) -> &'static str;
fn next_funky_thing(&'a self) -> &'a ListLink<'a, Funky<'a> + 'a>;
fn next_funky_thing(&'a self) -> &'a ListLink<'a, Funky<'a>>;
}

impl<'a> ListNode<'a, Funky<'a> + 'a> for Funky<'a> + 'a {
fn next(&'a self) -> &'a ListLink<'a, Funky<'a> + 'a> {
impl<'a> ListNode<'a, Funky<'a>> for Funky<'a> {
fn next(&'a self) -> &'a ListLink<'a, Funky<'a>> {
&self.next_funky_thing()
}
}

// A manager holds a list of funky things
pub struct Manager<'a> {
funky_things: List<'a, Funky<'a> + 'a>,
funky_things: List<'a, Funky<'a>>,
}

impl<'a> Manager<'a> {
Expand All @@ -41,7 +41,7 @@ impl<'a> Manager<'a> {
}
}

pub fn manage(&mut self, thing: &'a (Funky<'a> + 'a)) {
pub fn manage(&mut self, thing: &'a (Funky<'a>)) {
self.funky_things.push_head(thing);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ impl<'a> Funky<'a> for Jazz<'a> {
"Jazz"
}

fn next_funky_thing(&'a self) -> &'a ListLink<'a, Funky<'a> + 'a> {
fn next_funky_thing(&'a self) -> &'a ListLink<'a, Funky<'a>> {
&self.next
}
}
Expand All @@ -92,7 +92,7 @@ impl<'a> Funky<'a> for Cheese<'a> {
fn name(&self) -> &'static str {
"Cheese"
}
fn next_funky_thing(&'a self) -> &'a ListLink<'a, Funky<'a> + 'a> {
fn next_funky_thing(&'a self) -> &'a ListLink<'a, Funky<'a>> {
&self.next
}
}
10 changes: 5 additions & 5 deletions capsules/src/adc.rs
Expand Up @@ -40,7 +40,7 @@ pub const DRIVER_NUM: usize = 0x00000005;

/// ADC application driver, used by applications to interact with ADC.
/// Not currently virtualized, only one application can use it at a time.
pub struct Adc<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> {
pub struct Adc<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed> {
// ADC driver
adc: &'a A,
channels: &'a [&'a <A as hil::adc::Adc>::Channel],
Expand Down Expand Up @@ -100,7 +100,7 @@ pub static mut ADC_BUFFER2: [u16; 128] = [0; 128];
pub static mut ADC_BUFFER3: [u16; 128] = [0; 128];

/// Functions to create, initialize, and interact with the ADC
impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> Adc<'a, A> {
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> Adc<'a, A> {
/// Create a new Adc application interface
///
/// adc - ADC driver to provide application access to
Expand Down Expand Up @@ -466,7 +466,7 @@ impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> Adc<'a, A> {
}

/// Callbacks from the ADC driver
impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> hil::adc::Client for Adc<'a, A> {
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> hil::adc::Client for Adc<'a, A> {
/// Single sample operation complete
/// Collects the sample and provides a callback to the application
///
Expand Down Expand Up @@ -506,7 +506,7 @@ impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> hil::adc::Client for Ad
}

/// Callbacks from the High Speed ADC driver
impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> hil::adc::HighSpeedClient for Adc<'a, A> {
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> hil::adc::HighSpeedClient for Adc<'a, A> {
/// Internal buffer has filled from a buffered sampling operation.
/// Copies data over to application buffer, determines if more data is
/// needed, and performs a callback to the application if ready. If
Expand Down Expand Up @@ -763,7 +763,7 @@ impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> hil::adc::HighSpeedClie
}

/// Implementations of application syscalls
impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed + 'a> Driver for Adc<'a, A> {
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> Driver for Adc<'a, A> {
/// Provides access to a buffer from the application to store data in or
/// read data from
///
Expand Down
10 changes: 4 additions & 6 deletions capsules/src/aes_ccm.rs
Expand Up @@ -68,7 +68,7 @@ enum CCMState {
Encrypt,
}

pub struct AES128CCM<'a, A: AES128<'a> + AES128Ctr + AES128CBC + 'a> {
pub struct AES128CCM<'a, A: AES128<'a> + AES128Ctr + AES128CBC> {
aes: &'a A,
crypt_buf: TakeCell<'a, [u8]>,
crypt_auth_len: Cell<usize>,
Expand All @@ -86,7 +86,7 @@ pub struct AES128CCM<'a, A: AES128<'a> + AES128Ctr + AES128CBC + 'a> {
saved_tag: Cell<[u8; AES128_BLOCK_SIZE]>,
}

impl<'a, A: AES128<'a> + AES128Ctr + AES128CBC + 'a> AES128CCM<'a, A> {
impl<A: AES128<'a> + AES128Ctr + AES128CBC> AES128CCM<'a, A> {
pub fn new(aes: &'a A, crypt_buf: &'static mut [u8]) -> AES128CCM<'a, A> {
AES128CCM {
aes: aes,
Expand Down Expand Up @@ -414,7 +414,7 @@ impl<'a, A: AES128<'a> + AES128Ctr + AES128CBC + 'a> AES128CCM<'a, A> {
}
}

impl<'a, A: AES128<'a> + AES128Ctr + AES128CBC + 'a> symmetric_encryption::AES128CCM<'a>
impl<A: AES128<'a> + AES128Ctr + AES128CBC> symmetric_encryption::AES128CCM<'a>
for AES128CCM<'a, A>
{
fn set_client(&self, client: &'a symmetric_encryption::CCMClient) {
Expand Down Expand Up @@ -492,9 +492,7 @@ impl<'a, A: AES128<'a> + AES128Ctr + AES128CBC + 'a> symmetric_encryption::AES12
}
}

impl<'a, A: AES128<'a> + AES128Ctr + AES128CBC> symmetric_encryption::Client<'a>
for AES128CCM<'a, A>
{
impl<A: AES128<'a> + AES128Ctr + AES128CBC> symmetric_encryption::Client<'a> for AES128CCM<'a, A> {
fn crypt_done(&self, _: Option<&'a mut [u8]>, crypt_buf: &'a mut [u8]) {
self.crypt_buf.replace(crypt_buf);
match self.state.get() {
Expand Down
8 changes: 4 additions & 4 deletions capsules/src/alarm.rs
Expand Up @@ -28,14 +28,14 @@ impl Default for AlarmData {
}
}

pub struct AlarmDriver<'a, A: Alarm + 'a> {
pub struct AlarmDriver<'a, A: Alarm> {
alarm: &'a A,
num_armed: Cell<usize>,
app_alarm: Grant<AlarmData>,
prev: Cell<u32>,
}

impl<'a, A: Alarm> AlarmDriver<'a, A> {
impl<A: Alarm> AlarmDriver<'a, A> {
pub const fn new(alarm: &'a A, grant: Grant<AlarmData>) -> AlarmDriver<'a, A> {
AlarmDriver {
alarm: alarm,
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<'a, A: Alarm> AlarmDriver<'a, A> {
}
}

impl<'a, A: Alarm> Driver for AlarmDriver<'a, A> {
impl<A: Alarm> Driver for AlarmDriver<'a, A> {
/// Subscribe to alarm expiration
///
/// ### `_subscribe_num`
Expand Down Expand Up @@ -161,7 +161,7 @@ fn has_expired(alarm: u32, now: u32, prev: u32) -> bool {
now.wrapping_sub(prev) >= alarm.wrapping_sub(prev)
}

impl<'a, A: Alarm> time::Client for AlarmDriver<'a, A> {
impl<A: Alarm> time::Client for AlarmDriver<'a, A> {
fn fired(&self) {
let now = self.alarm.now();
self.app_alarm.each(|alarm| {
Expand Down
6 changes: 3 additions & 3 deletions capsules/src/ambient_light.rs
Expand Up @@ -30,7 +30,7 @@ pub struct AmbientLight<'a> {
apps: Grant<App>,
}

impl<'a> AmbientLight<'a> {
impl AmbientLight<'a> {
pub fn new(sensor: &'a hil::sensors::AmbientLight, grant: Grant<App>) -> AmbientLight {
AmbientLight {
sensor: sensor,
Expand All @@ -57,7 +57,7 @@ impl<'a> AmbientLight<'a> {
}
}

impl<'a> Driver for AmbientLight<'a> {
impl Driver for AmbientLight<'a> {
/// Subscribe to light intensity readings
///
/// ### `subscribe`
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a> Driver for AmbientLight<'a> {
}
}

impl<'a> hil::sensors::AmbientLightClient for AmbientLight<'a> {
impl hil::sensors::AmbientLightClient for AmbientLight<'a> {
fn callback(&self, lux: usize) {
self.command_pending.set(false);
self.apps.each(|app| {
Expand Down
6 changes: 3 additions & 3 deletions capsules/src/app_flash_driver.rs
Expand Up @@ -54,7 +54,7 @@ pub struct AppFlash<'a> {
buffer: TakeCell<'static, [u8]>,
}

impl<'a> AppFlash<'a> {
impl AppFlash<'a> {
pub fn new(
driver: &'a hil::nonvolatile_storage::NonvolatileStorage,
grant: Grant<App>,
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'a> AppFlash<'a> {
}
}

impl<'a> hil::nonvolatile_storage::NonvolatileStorageClient for AppFlash<'a> {
impl hil::nonvolatile_storage::NonvolatileStorageClient for AppFlash<'a> {
fn read_done(&self, _buffer: &'static mut [u8], _length: usize) {}

fn write_done(&self, buffer: &'static mut [u8], _length: usize) {
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<'a> hil::nonvolatile_storage::NonvolatileStorageClient for AppFlash<'a> {
}
}

impl<'a> Driver for AppFlash<'a> {
impl Driver for AppFlash<'a> {
/// Setup buffer to write from.
///
/// ### `allow_num`
Expand Down
38 changes: 19 additions & 19 deletions capsules/src/ble_advertising_driver.rs
Expand Up @@ -231,8 +231,8 @@ impl App {

fn send_advertisement<'a, B, A>(&self, ble: &BLE<'a, B, A>, channel: RadioChannel) -> ReturnCode
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
self.adv_data
.as_ref()
Expand Down Expand Up @@ -300,8 +300,8 @@ impl App {

pub struct BLE<'a, B, A>
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
radio: &'a B,
busy: Cell<bool>,
Expand All @@ -312,10 +312,10 @@ where
receiving_app: Cell<Option<kernel::AppId>>,
}

impl<'a, B, A> BLE<'a, B, A>
impl<B, A> BLE<'a, B, A>
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
pub fn new(
radio: &'a B,
Expand Down Expand Up @@ -364,10 +364,10 @@ where
}

// Timer alarm
impl<'a, B, A> kernel::hil::time::Client for BLE<'a, B, A>
impl<B, A> kernel::hil::time::Client for BLE<'a, B, A>
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
// When an alarm is fired, we find which apps have expired timers. Expired
// timers indicate a desire to perform some operation (e.g. start an
Expand Down Expand Up @@ -433,10 +433,10 @@ where
}

// Callback from the radio once a RX event occur
impl<'a, B, A> ble_advertising::RxClient for BLE<'a, B, A>
impl<B, A> ble_advertising::RxClient for BLE<'a, B, A>
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
fn receive_event(&self, buf: &'static mut [u8], len: u8, result: ReturnCode) {
if let Some(appid) = self.receiving_app.get() {
Expand Down Expand Up @@ -500,10 +500,10 @@ where
}

// Callback from the radio once a TX event occur
impl<'a, B, A> ble_advertising::TxClient for BLE<'a, B, A>
impl<B, A> ble_advertising::TxClient for BLE<'a, B, A>
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
// The ReturnCode indicates valid CRC or not, not used yet but could be used for
// re-transmissions for invalid CRCs
Expand Down Expand Up @@ -541,10 +541,10 @@ where
}

// System Call implementation
impl<'a, B, A> kernel::Driver for BLE<'a, B, A>
impl<B, A> kernel::Driver for BLE<'a, B, A>
where
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig + 'a,
A: kernel::hil::time::Alarm + 'a,
B: ble_advertising::BleAdvertisementDriver + ble_advertising::BleConfig,
A: kernel::hil::time::Alarm,
{
fn command(
&self,
Expand Down

0 comments on commit 5b410e3

Please sign in to comment.