Skip to content

Instantly share code, notes, and snippets.

@tamird
Created November 9, 2021 22:28
Show Gist options
  • Save tamird/08c127731fe7fed752f5b19f8bac26a6 to your computer and use it in GitHub Desktop.
Save tamird/08c127731fe7fed752f5b19f8bac26a6 to your computer and use it in GitHub Desktop.
pub(crate) trait Transport<I: Ip> {
type SocketCollection;
}
pub(crate) enum Udp {}
impl<I: Ip> Transport<I> for Udp {
type SocketCollection = UdpSocketCollection<I>;
}
pub(crate) struct SocketCollection<T>
where
T: Transport<Ipv4>,
T: Transport<Ipv6>,
{
v4: <T as Transport<Ipv4>>::SocketCollection,
v6: <T as Transport<Ipv6>>::SocketCollection,
}
impl<T> Default for SocketCollection<T>
where
T: Transport<Ipv4>,
T: Transport<Ipv6>,
<T as Transport<Ipv4>>::SocketCollection: Default,
<T as Transport<Ipv6>>::SocketCollection: Default,
{
fn default() -> Self {
Self { v4: Default::default(), v6: Default::default() }
}
}
pub(crate) trait SocketCollectionExt<T>: Ip
where
T: Transport<Ipv4>,
T: Transport<Ipv6>,
T: Transport<Self>,
{
fn get_collection<D: AsRef<SocketCollection<T>>>(
dispatcher: &D,
) -> &<T as Transport<Self>>::SocketCollection;
fn get_collection_mut<D: AsMut<SocketCollection<T>>>(
dispatcher: &mut D,
) -> &mut <T as Transport<Self>>::SocketCollection;
}
impl<T> SocketCollectionExt<T> for Ipv4
where
T: Transport<Ipv4>,
T: Transport<Ipv6>,
{
fn get_collection<D: AsRef<SocketCollection<T>>>(
dispatcher: &D,
) -> &<T as Transport<Self>>::SocketCollection {
&dispatcher.as_ref().v4
}
fn get_collection_mut<D: AsMut<SocketCollection<T>>>(
dispatcher: &mut D,
) -> &mut <T as Transport<Self>>::SocketCollection {
&mut dispatcher.as_mut().v4
}
}
impl<T> SocketCollectionExt<T> for Ipv6
where
T: Transport<Ipv4>,
T: Transport<Ipv6>,
{
fn get_collection<D: AsRef<SocketCollection<T>>>(
dispatcher: &D,
) -> &<T as Transport<Self>>::SocketCollection {
&dispatcher.as_ref().v6
}
fn get_collection_mut<D: AsMut<SocketCollection<T>>>(
dispatcher: &mut D,
) -> &mut <T as Transport<Self>>::SocketCollection {
&mut dispatcher.as_mut().v6
}
}
error[E0311]: the parameter type `T` may not live long enough
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:100:21
|
100 | &dispatcher.as_ref().v4
| ^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:98:21
|
98 | dispatcher: &D,
| ^^
note: ...so that the reference type `&SocketCollection<T>` does not outlive the data it points at
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:100:21
|
100 | &dispatcher.as_ref().v4
| ^^^^^^
error[E0311]: the parameter type `T` may not live long enough
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:106:25
|
106 | &mut dispatcher.as_mut().v4
| ^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:104:21
|
104 | dispatcher: &mut D,
| ^^^^^^
note: ...so that the reference type `&mut SocketCollection<T>` does not outlive the data it points at
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:106:25
|
106 | &mut dispatcher.as_mut().v4
| ^^^^^^
error[E0311]: the parameter type `T` may not live long enough
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:118:21
|
118 | &dispatcher.as_ref().v6
| ^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:116:21
|
116 | dispatcher: &D,
| ^^
note: ...so that the reference type `&SocketCollection<T>` does not outlive the data it points at
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:118:21
|
118 | &dispatcher.as_ref().v6
| ^^^^^^
error[E0311]: the parameter type `T` may not live long enough
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:124:25
|
124 | &mut dispatcher.as_mut().v6
| ^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:122:21
|
122 | dispatcher: &mut D,
| ^^^^^^
note: ...so that the reference type `&mut SocketCollection<T>` does not outlive the data it points at
--> ../../src/connectivity/network/netstack3/src/bindings/socket/datagram.rs:124:25
|
124 | &mut dispatcher.as_mut().v6
| ^^^^^^
error: aborting due to 4 previous errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment