Fix lifetime variance.

This commit is contained in:
whitequark 2016-12-17 06:27:08 +00:00
parent 666b615171
commit 2dc837be9d
4 changed files with 28 additions and 28 deletions

View File

@ -17,26 +17,26 @@ use super::{ArpCache};
/// 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.
#[derive(Debug)]
pub struct Interface<'a,
pub struct Interface<'a, 'b: 'a,
DeviceT: Device,
ArpCacheT: ArpCache,
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
SocketsT: BorrowMut<[Socket<'a>]>
SocketsT: BorrowMut<[Socket<'a, 'b>]>
> {
device: DeviceT,
arp_cache: ArpCacheT,
hardware_addr: EthernetAddress,
protocol_addrs: ProtocolAddrsT,
sockets: SocketsT,
phantom: PhantomData<Socket<'a>>
phantom: PhantomData<Socket<'a, 'b>>
}
impl<'a,
impl<'a, 'b: 'a,
DeviceT: Device,
ArpCacheT: ArpCache,
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
SocketsT: BorrowMut<[Socket<'a>]>
> Interface<'a, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
SocketsT: BorrowMut<[Socket<'a, 'b>]>
> Interface<'a, 'b, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
/// Create a network interface using the provided network device.
///
/// # Panics
@ -44,7 +44,7 @@ impl<'a,
/// and [set_protocol_addrs](#method.set_protocol_addrs) functions.
pub fn new(device: DeviceT, arp_cache: ArpCacheT, hardware_addr: EthernetAddress,
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_protocol_addrs(protocol_addrs.borrow());
Interface {
@ -106,7 +106,7 @@ impl<'a,
}
/// 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()
}

View File

@ -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> {
fn from(value: &'a mut T) -> Self {
impl<'a, 'b: 'a, T: 'b + ?Sized> From<&'b mut T> for Managed<'b, T> {
fn from(value: &'b mut T) -> Self {
Managed::Borrowed(value)
}
}

View File

@ -44,13 +44,13 @@ pub trait PacketRepr {
/// 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
/// since the lower layers treat the packet as an opaque octet sequence.
pub enum Socket<'a> {
Udp(UdpSocket<'a>),
pub enum Socket<'a, 'b: 'a> {
Udp(UdpSocket<'a, 'b>),
#[doc(hidden)]
__Nonexhaustive
}
impl<'a> Socket<'a> {
impl<'a, 'b> Socket<'a, 'b> {
/// Process a packet received from a network interface.
///
/// 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;
}
impl<'a> AsSocket<UdpSocket<'a>> for Socket<'a> {
fn as_socket(&mut self) -> &mut UdpSocket<'a> {
impl<'a, 'b> AsSocket<UdpSocket<'a, 'b>> for Socket<'a, 'b> {
fn as_socket(&mut self) -> &mut UdpSocket<'a, 'b> {
match self {
&mut Socket::Udp(ref mut socket) => socket,
_ => panic!(".as_socket::<UdpSocket> called on wrong socket type")

View File

@ -37,16 +37,16 @@ impl<'a> BufferElem<'a> {
/// An UDP packet buffer.
#[derive(Debug)]
pub struct Buffer<'a> {
storage: Managed<'a, [BufferElem<'a>]>,
pub struct Buffer<'a, 'b: 'a> {
storage: Managed<'a, [BufferElem<'b>]>,
read_at: usize,
length: usize
}
impl<'a> Buffer<'a> {
impl<'a, 'b> Buffer<'a, 'b> {
/// Create a packet buffer with the given storage.
pub fn new<T>(storage: T) -> Buffer<'a>
where T: Into<Managed<'a, [BufferElem<'a>]>> {
pub fn new<T>(storage: T) -> Buffer<'a, 'b>
where T: Into<Managed<'a, [BufferElem<'b>]>> {
let mut storage = storage.into();
for elem in storage.iter_mut() {
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
/// `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() {
Err(Error::Exhausted)
} else {
@ -91,7 +91,7 @@ impl<'a> Buffer<'a> {
/// Dequeue an element from the buffer, and return a pointer to it, or return
/// `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() {
Err(Error::Exhausted)
} else {
@ -107,16 +107,16 @@ impl<'a> Buffer<'a> {
///
/// An UDP socket is bound to a specific endpoint, and owns transmit and receive
/// packet buffers.
pub struct UdpSocket<'a> {
pub struct UdpSocket<'a, 'b: 'a> {
endpoint: Endpoint,
rx_buffer: Buffer<'a>,
tx_buffer: Buffer<'a>
rx_buffer: Buffer<'a, 'b>,
tx_buffer: Buffer<'a, 'b>
}
impl<'a> UdpSocket<'a> {
impl<'a, 'b> UdpSocket<'a, 'b> {
/// Create an UDP socket with the given buffers.
pub fn new(endpoint: Endpoint, rx_buffer: Buffer<'a>, tx_buffer: Buffer<'a>)
-> Socket<'a> {
pub fn new(endpoint: Endpoint, rx_buffer: Buffer<'a, 'b>, tx_buffer: Buffer<'a, 'b>)
-> Socket<'a, 'b> {
Socket::Udp(UdpSocket {
endpoint: endpoint,
rx_buffer: rx_buffer,