I have this trait:
pub trait Device<'a> {
type RxToken: RxToken + 'a;
type TxToken: TxToken + 'a;
And my implementation for it does the followiing:
impl<'a: 'd, 'd> Device<'d> for VirtualTunInterface<'a> {
type RxToken = RxToken;
type TxToken = TxToken<'a>;
for the struct
#[derive(Clone)]
pub struct VirtualTunInterface<'a> {
mtu: usize,
packets_from_inside: Arc<Mutex<VecDeque<Vec<u8>>>>,
packets_from_outside: Arc<Mutex<VecDeque<Blob<'a>>>>,
}
I have this struct that uses DeviceT
which is implemented for all lifetimes:
pub struct SmolStack<'a, 'b: 'a, 'c: 'a + 'b, DeviceT>
where
DeviceT: for<'d> Device<'d>,
{
And the error happens on this enum that uses that struct:
pub enum SmolStackType<'a, 'b: 'a, 'c: 'a + 'b> {
VirtualTun(SmolStack<'a, 'b, 'c, VirtualTunDevice<'a>>),
Tun(SmolStack<'a, 'b, 'c, TunDevice>),
}
I'm getting this error right at VirtualTun(SmolStack...
:
error: implementation of `virtual_tun::smoltcp::phy::Device` is not general enough
--> src/virtual_tun/interface.rs:39:16
|
39 | VirtualTun(SmolStack<'a, 'b, 'c, VirtualTunDevice<'a>>),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `virtual_tun::smoltcp::phy::Device` is not general enough
|
::: /root/.cargo/git/checkouts/smoltcp-6b7a435d708e03f1/2e784fc/src/phy/mod.rs:260:1
|
260 | / pub trait Device<'a> {
261 | | type RxToken: RxToken + 'a;
262 | | type TxToken: TxToken + 'a;
263 | |
... |
279 | | fn medium(&self) -> Medium;
280 | | }
| |_- trait `virtual_tun::smoltcp::phy::Device` defined here
|
= note: `virtual_tun::smoltcp::phy::Device<'0>` would have to be implemented for the type `virtual_tun::virtual_tun::VirtualTunInterface<'a>`, for any lifetime `'0`...
= note: ...but `virtual_tun::smoltcp::phy::Device<'_>` is actually implemented for the type `virtual_tun::virtual_tun::VirtualTunInterface<'1>`, for some specific lifetime `'1`
(VirtualTunInterface
is the same as VirtualTunDevice
)
If I understood correctly, the error happens because I'm implementing Device
like this: impl<'a: 'd, 'd> Device<'d> for VirtualTunInterface<'a> {
, for some lifetime 'a
for VirtualTunInterface
, but I should implement for all lifetimes of VirtualTunInterface
. I don't get it, because for VirtualTunInterface<'a>
already means for type VirtualTunInterface with some generic lifetime
. What would implementing for all lifetimes look like?
Entire source if needed: smoltcp_cpp_interface/virtual_tun.rs at 1e55dd6e4454404dcdefb0fef31fd81e1dc06907 · lattice0/smoltcp_cpp_interface · GitHub