Fix lifetime variance.
This commit is contained in:
parent
666b615171
commit
2dc837be9d
|
@ -17,26 +17,26 @@ use super::{ArpCache};
|
||||||
/// a dependency on heap allocation, it instead owns a `BorrowMut<[T]>`, which can be
|
/// a dependency on heap allocation, it instead owns a `BorrowMut<[T]>`, which can be
|
||||||
/// a `&mut [T]`, or `Vec<T>` if a heap is available.
|
/// a `&mut [T]`, or `Vec<T>` if a heap is available.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Interface<'a,
|
pub struct Interface<'a, 'b: 'a,
|
||||||
DeviceT: Device,
|
DeviceT: Device,
|
||||||
ArpCacheT: ArpCache,
|
ArpCacheT: ArpCache,
|
||||||
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
|
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
|
||||||
SocketsT: BorrowMut<[Socket<'a>]>
|
SocketsT: BorrowMut<[Socket<'a, 'b>]>
|
||||||
> {
|
> {
|
||||||
device: DeviceT,
|
device: DeviceT,
|
||||||
arp_cache: ArpCacheT,
|
arp_cache: ArpCacheT,
|
||||||
hardware_addr: EthernetAddress,
|
hardware_addr: EthernetAddress,
|
||||||
protocol_addrs: ProtocolAddrsT,
|
protocol_addrs: ProtocolAddrsT,
|
||||||
sockets: SocketsT,
|
sockets: SocketsT,
|
||||||
phantom: PhantomData<Socket<'a>>
|
phantom: PhantomData<Socket<'a, 'b>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a,
|
impl<'a, 'b: 'a,
|
||||||
DeviceT: Device,
|
DeviceT: Device,
|
||||||
ArpCacheT: ArpCache,
|
ArpCacheT: ArpCache,
|
||||||
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
|
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
|
||||||
SocketsT: BorrowMut<[Socket<'a>]>
|
SocketsT: BorrowMut<[Socket<'a, 'b>]>
|
||||||
> Interface<'a, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
|
> Interface<'a, 'b, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
|
||||||
/// Create a network interface using the provided network device.
|
/// Create a network interface using the provided network device.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
|
@ -44,7 +44,7 @@ impl<'a,
|
||||||
/// and [set_protocol_addrs](#method.set_protocol_addrs) functions.
|
/// and [set_protocol_addrs](#method.set_protocol_addrs) functions.
|
||||||
pub fn new(device: DeviceT, arp_cache: ArpCacheT, hardware_addr: EthernetAddress,
|
pub fn new(device: DeviceT, arp_cache: ArpCacheT, hardware_addr: EthernetAddress,
|
||||||
protocol_addrs: ProtocolAddrsT, sockets: SocketsT) ->
|
protocol_addrs: ProtocolAddrsT, sockets: SocketsT) ->
|
||||||
Interface<'a, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
|
Interface<'a, 'b, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
|
||||||
Self::check_hardware_addr(&hardware_addr);
|
Self::check_hardware_addr(&hardware_addr);
|
||||||
Self::check_protocol_addrs(protocol_addrs.borrow());
|
Self::check_protocol_addrs(protocol_addrs.borrow());
|
||||||
Interface {
|
Interface {
|
||||||
|
@ -106,7 +106,7 @@ impl<'a,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the set of sockets owned by the interface.
|
/// Get the set of sockets owned by the interface.
|
||||||
pub fn sockets(&mut self) -> &mut [Socket<'a>] {
|
pub fn sockets(&mut self) -> &mut [Socket<'a, 'b>] {
|
||||||
self.sockets.borrow_mut()
|
self.sockets.borrow_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ impl<'a, T: 'a + fmt::Debug + ?Sized> fmt::Debug for Managed<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: 'a + ?Sized> From<&'a mut T> for Managed<'a, T> {
|
impl<'a, 'b: 'a, T: 'b + ?Sized> From<&'b mut T> for Managed<'b, T> {
|
||||||
fn from(value: &'a mut T) -> Self {
|
fn from(value: &'b mut T) -> Self {
|
||||||
Managed::Borrowed(value)
|
Managed::Borrowed(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ pub trait PacketRepr {
|
||||||
/// which is rather inelegant. Conversely, when `dispatch` is called, the packet length is
|
/// which is rather inelegant. Conversely, when `dispatch` is called, the packet length is
|
||||||
/// not yet known and the packet storage has to be allocated; but the `&PacketRepr` is sufficient
|
/// not yet known and the packet storage has to be allocated; but the `&PacketRepr` is sufficient
|
||||||
/// since the lower layers treat the packet as an opaque octet sequence.
|
/// since the lower layers treat the packet as an opaque octet sequence.
|
||||||
pub enum Socket<'a> {
|
pub enum Socket<'a, 'b: 'a> {
|
||||||
Udp(UdpSocket<'a>),
|
Udp(UdpSocket<'a, 'b>),
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
__Nonexhaustive
|
__Nonexhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Socket<'a> {
|
impl<'a, 'b> Socket<'a, 'b> {
|
||||||
/// Process a packet received from a network interface.
|
/// Process a packet received from a network interface.
|
||||||
///
|
///
|
||||||
/// This function checks if the packet contained in the payload matches the socket endpoint,
|
/// This function checks if the packet contained in the payload matches the socket endpoint,
|
||||||
|
@ -94,8 +94,8 @@ pub trait AsSocket<T> {
|
||||||
fn as_socket(&mut self) -> &mut T;
|
fn as_socket(&mut self) -> &mut T;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsSocket<UdpSocket<'a>> for Socket<'a> {
|
impl<'a, 'b> AsSocket<UdpSocket<'a, 'b>> for Socket<'a, 'b> {
|
||||||
fn as_socket(&mut self) -> &mut UdpSocket<'a> {
|
fn as_socket(&mut self) -> &mut UdpSocket<'a, 'b> {
|
||||||
match self {
|
match self {
|
||||||
&mut Socket::Udp(ref mut socket) => socket,
|
&mut Socket::Udp(ref mut socket) => socket,
|
||||||
_ => panic!(".as_socket::<UdpSocket> called on wrong socket type")
|
_ => panic!(".as_socket::<UdpSocket> called on wrong socket type")
|
||||||
|
|
|
@ -37,16 +37,16 @@ impl<'a> BufferElem<'a> {
|
||||||
|
|
||||||
/// An UDP packet buffer.
|
/// An UDP packet buffer.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Buffer<'a> {
|
pub struct Buffer<'a, 'b: 'a> {
|
||||||
storage: Managed<'a, [BufferElem<'a>]>,
|
storage: Managed<'a, [BufferElem<'b>]>,
|
||||||
read_at: usize,
|
read_at: usize,
|
||||||
length: usize
|
length: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Buffer<'a> {
|
impl<'a, 'b> Buffer<'a, 'b> {
|
||||||
/// Create a packet buffer with the given storage.
|
/// Create a packet buffer with the given storage.
|
||||||
pub fn new<T>(storage: T) -> Buffer<'a>
|
pub fn new<T>(storage: T) -> Buffer<'a, 'b>
|
||||||
where T: Into<Managed<'a, [BufferElem<'a>]>> {
|
where T: Into<Managed<'a, [BufferElem<'b>]>> {
|
||||||
let mut storage = storage.into();
|
let mut storage = storage.into();
|
||||||
for elem in storage.iter_mut() {
|
for elem in storage.iter_mut() {
|
||||||
elem.endpoint = Default::default();
|
elem.endpoint = Default::default();
|
||||||
|
@ -78,7 +78,7 @@ impl<'a> Buffer<'a> {
|
||||||
|
|
||||||
/// Enqueue an element into the buffer, and return a pointer to it, or return
|
/// Enqueue an element into the buffer, and return a pointer to it, or return
|
||||||
/// `Err(Error::Exhausted)` if the buffer is full.
|
/// `Err(Error::Exhausted)` if the buffer is full.
|
||||||
pub fn enqueue(&mut self) -> Result<&mut BufferElem<'a>, Error> {
|
pub fn enqueue(&mut self) -> Result<&mut BufferElem<'b>, Error> {
|
||||||
if self.full() {
|
if self.full() {
|
||||||
Err(Error::Exhausted)
|
Err(Error::Exhausted)
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,7 +91,7 @@ impl<'a> Buffer<'a> {
|
||||||
|
|
||||||
/// Dequeue an element from the buffer, and return a pointer to it, or return
|
/// Dequeue an element from the buffer, and return a pointer to it, or return
|
||||||
/// `Err(Error::Exhausted)` if the buffer is empty.
|
/// `Err(Error::Exhausted)` if the buffer is empty.
|
||||||
pub fn dequeue(&mut self) -> Result<&BufferElem<'a>, Error> {
|
pub fn dequeue(&mut self) -> Result<&BufferElem<'b>, Error> {
|
||||||
if self.empty() {
|
if self.empty() {
|
||||||
Err(Error::Exhausted)
|
Err(Error::Exhausted)
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,16 +107,16 @@ impl<'a> Buffer<'a> {
|
||||||
///
|
///
|
||||||
/// An UDP socket is bound to a specific endpoint, and owns transmit and receive
|
/// An UDP socket is bound to a specific endpoint, and owns transmit and receive
|
||||||
/// packet buffers.
|
/// packet buffers.
|
||||||
pub struct UdpSocket<'a> {
|
pub struct UdpSocket<'a, 'b: 'a> {
|
||||||
endpoint: Endpoint,
|
endpoint: Endpoint,
|
||||||
rx_buffer: Buffer<'a>,
|
rx_buffer: Buffer<'a, 'b>,
|
||||||
tx_buffer: Buffer<'a>
|
tx_buffer: Buffer<'a, 'b>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> UdpSocket<'a> {
|
impl<'a, 'b> UdpSocket<'a, 'b> {
|
||||||
/// Create an UDP socket with the given buffers.
|
/// Create an UDP socket with the given buffers.
|
||||||
pub fn new(endpoint: Endpoint, rx_buffer: Buffer<'a>, tx_buffer: Buffer<'a>)
|
pub fn new(endpoint: Endpoint, rx_buffer: Buffer<'a, 'b>, tx_buffer: Buffer<'a, 'b>)
|
||||||
-> Socket<'a> {
|
-> Socket<'a, 'b> {
|
||||||
Socket::Udp(UdpSocket {
|
Socket::Udp(UdpSocket {
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
rx_buffer: rx_buffer,
|
rx_buffer: rx_buffer,
|
||||||
|
|
Loading…
Reference in New Issue