@@ -20,6 +20,8 @@ An implementation of the [Device](trait.Device.html) trait for a simple hardware
20
20
Ethernet controller could look as follows:
21
21
22
22
```rust
23
+ # #![feature(generic_associated_types)]
24
+
23
25
use smoltcp::Result;
24
26
use smoltcp::phy::{self, DeviceCapabilities, Device, Medium};
25
27
use smoltcp::time::Instant;
@@ -38,16 +40,16 @@ impl<'a> StmPhy {
38
40
}
39
41
}
40
42
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>;
44
46
45
- fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
47
+ fn receive(&mut self) -> Option<(Self::RxToken<'_> , Self::TxToken<'_> )> {
46
48
Some((StmPhyRxToken(&mut self.rx_buffer[..]),
47
49
StmPhyTxToken(&mut self.tx_buffer[..])))
48
50
}
49
51
50
- fn transmit(&'a mut self) -> Option<Self::TxToken> {
52
+ fn transmit(&mut self) -> Option<Self::TxToken<'_> > {
51
53
Some(StmPhyTxToken(&mut self.tx_buffer[..]))
52
54
}
53
55
@@ -312,20 +314,24 @@ impl Default for Medium {
312
314
/// The interface is based on _tokens_, which are types that allow to receive/transmit a
313
315
/// single packet. The `receive` and `transmit` functions only construct such tokens, the
314
316
/// 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 ;
318
324
319
325
/// Construct a token pair consisting of one receive token and one transmit token.
320
326
///
321
327
/// The additional transmit token makes it possible to generate a reply packet based
322
328
/// on the contents of the received packet. For example, this makes it possible to
323
329
/// handle arbitrarily large ICMP echo ("ping") requests, where the all received bytes
324
330
/// 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 < ' _ > ) > ;
326
332
327
333
/// Construct a transmit token.
328
- fn transmit ( & ' a mut self ) -> Option < Self :: TxToken > ;
334
+ fn transmit ( & mut self ) -> Option < Self :: TxToken < ' _ > > ;
329
335
330
336
/// Get a description of device capabilities.
331
337
fn capabilities ( & self ) -> DeviceCapabilities ;
0 commit comments