Skip to content

Commit

Permalink
Simplify SocketSet lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Jan 19, 2021
1 parent 8aed248 commit 43cf6ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/dhcp/clientv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Client {
/// Instant::now()
/// );
/// ```
pub fn new<'a, 'b>(sockets: &mut SocketSet<'a, 'b>, rx_buffer: RawSocketBuffer<'b>, tx_buffer: RawSocketBuffer<'b>, now: Instant) -> Self
pub fn new<'a>(sockets: &mut SocketSet<'a>, rx_buffer: RawSocketBuffer<'a>, tx_buffer: RawSocketBuffer<'a>, now: Instant) -> Self
{
let raw_socket = RawSocket::new(IpVersion::Ipv4, IpProtocol::Udp, rx_buffer, tx_buffer);
let raw_handle = sockets.add(raw_socket);
Expand Down
2 changes: 1 addition & 1 deletion src/iface/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ mod test {
use super::{EthernetPacket, IpPacket};

fn create_loopback<'a, 'b, 'c>() -> (EthernetInterface<'static, 'b, 'c, Loopback>,
SocketSet<'static, 'a>) {
SocketSet<'a>) {
// Create a basic device
let device = Loopback::new();
let ip_addrs = [
Expand Down
26 changes: 13 additions & 13 deletions src/socket/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ impl fmt::Display for Handle {

/// An extensible set of sockets.
///
/// The lifetime `'b` is used when storing a `Socket<'b>`.
/// The lifetime `'a` is used when storing a `Socket<'a>`.
#[derive(Debug)]
pub struct Set<'a, 'b: 'a> {
sockets: ManagedSlice<'a, Option<Item<'b>>>
pub struct Set<'a> {
sockets: ManagedSlice<'a, Option<Item<'a>>>
}

impl<'a, 'b: 'a> Set<'a, 'b> {
impl<'a> Set<'a> {
/// Create a socket set using the provided storage.
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a, 'b>
where SocketsT: Into<ManagedSlice<'a, Option<Item<'b>>>> {
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a>
where SocketsT: Into<ManagedSlice<'a, Option<Item<'a>>>> {
let sockets = sockets.into();
Set { sockets }
}
Expand All @@ -46,10 +46,10 @@ impl<'a, 'b: 'a> Set<'a, 'b> {
/// # Panics
/// This function panics if the storage is fixed-size (not a `Vec`) and is full.
pub fn add<T>(&mut self, socket: T) -> Handle
where T: Into<Socket<'b>>
where T: Into<Socket<'a>>
{
fn put<'b>(index: usize, slot: &mut Option<Item<'b>>,
mut socket: Socket<'b>) -> Handle {
fn put<'a>(index: usize, slot: &mut Option<Item<'a>>,
mut socket: Socket<'a>) -> Handle {
net_trace!("[{}]: adding", index);
let handle = Handle(index);
socket.meta_mut().handle = handle;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'a, 'b: 'a> Set<'a, 'b> {
/// # Panics
/// This function may panic if the handle does not belong to this socket set
/// or the socket has the wrong type.
pub fn get<T: AnySocket<'b>>(&mut self, handle: Handle) -> SocketRef<T> {
pub fn get<T: AnySocket<'a>>(&mut self, handle: Handle) -> SocketRef<T> {
match self.sockets[handle.0].as_mut() {
Some(item) => {
T::downcast(SocketRef::new(&mut item.socket))
Expand All @@ -97,7 +97,7 @@ impl<'a, 'b: 'a> Set<'a, 'b> {
///
/// # Panics
/// This function may panic if the handle does not belong to this socket set.
pub fn remove(&mut self, handle: Handle) -> Socket<'b> {
pub fn remove(&mut self, handle: Handle) -> Socket<'a> {
net_trace!("[{}]: removing", handle.0);
match self.sockets[handle.0].take() {
Some(item) => item.socket,
Expand Down Expand Up @@ -165,12 +165,12 @@ impl<'a, 'b: 'a> Set<'a, 'b> {
}

/// Iterate every socket in this set.
pub fn iter<'d>(&'d self) -> Iter<'d, 'b> {
pub fn iter<'d>(&'d self) -> Iter<'d, 'a> {
Iter { lower: self.sockets.iter() }
}

/// Iterate every socket in this set, as SocketRef.
pub fn iter_mut<'d>(&'d mut self) -> IterMut<'d, 'b> {
pub fn iter_mut<'d>(&'d mut self) -> IterMut<'d, 'a> {
IterMut { lower: self.sockets.iter_mut() }
}
}
Expand Down

0 comments on commit 43cf6ca

Please sign in to comment.