@@ -20,6 +20,8 @@ An implementation of the [Device](trait.Device.html) trait for a simple hardware
2020Ethernet controller could look as follows:
2121
2222```rust
23+ # #![feature(generic_associated_types)]
24+
2325use smoltcp::Result;
2426use smoltcp::phy::{self, DeviceCapabilities, Device, Medium};
2527use smoltcp::time::Instant;
@@ -38,16 +40,16 @@ impl<'a> StmPhy {
3840 }
3941}
4042
41- impl<'a> phy::Device<'a> for StmPhy {
42- type RxToken = StmPhyRxToken<'a>;
43- type TxToken = StmPhyTxToken<'a>;
43+ impl phy::Device for StmPhy {
44+ type RxToken<'a> where Self: 'a = StmPhyRxToken<'a>;
45+ type TxToken<'a> where Self: 'a = StmPhyTxToken<'a>;
4446
45- fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
47+ fn receive(&mut self) -> Option<(Self::RxToken<'_> , Self::TxToken<'_> )> {
4648 Some((StmPhyRxToken(&mut self.rx_buffer[..]),
4749 StmPhyTxToken(&mut self.tx_buffer[..])))
4850 }
4951
50- fn transmit(&'a mut self) -> Option<Self::TxToken> {
52+ fn transmit(&mut self) -> Option<Self::TxToken<'_> > {
5153 Some(StmPhyTxToken(&mut self.tx_buffer[..]))
5254 }
5355
@@ -312,20 +314,24 @@ impl Default for Medium {
312314/// The interface is based on _tokens_, which are types that allow to receive/transmit a
313315/// single packet. The `receive` and `transmit` functions only construct such tokens, the
314316/// real sending/receiving operation are performed when the tokens are consumed.
315- pub trait Device < ' a > {
316- type RxToken : RxToken + ' a ;
317- type TxToken : TxToken + ' a ;
317+ pub trait Device {
318+ type RxToken < ' a > : RxToken
319+ where
320+ Self : ' a ;
321+ type TxToken < ' a > : TxToken
322+ where
323+ Self : ' a ;
318324
319325 /// Construct a token pair consisting of one receive token and one transmit token.
320326 ///
321327 /// The additional transmit token makes it possible to generate a reply packet based
322328 /// on the contents of the received packet. For example, this makes it possible to
323329 /// handle arbitrarily large ICMP echo ("ping") requests, where the all received bytes
324330 /// need to be sent back, without heap allocation.
325- fn receive ( & ' a mut self ) -> Option < ( Self :: RxToken , Self :: TxToken ) > ;
331+ fn receive ( & mut self ) -> Option < ( Self :: RxToken < ' _ > , Self :: TxToken < ' _ > ) > ;
326332
327333 /// Construct a transmit token.
328- fn transmit ( & ' a mut self ) -> Option < Self :: TxToken > ;
334+ fn transmit ( & mut self ) -> Option < Self :: TxToken < ' _ > > ;
329335
330336 /// Get a description of device capabilities.
331337 fn capabilities ( & self ) -> DeviceCapabilities ;
0 commit comments