From c3e07dad9ae16855cb80d05a022f9e8b70668616 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 8 Nov 2017 10:20:50 +0100 Subject: [PATCH] Store plain DeviceT instead of Managed<_> in EthernetInterface --- examples/client.rs | 2 +- examples/loopback.rs | 6 +++--- examples/ping.rs | 2 +- examples/server.rs | 2 +- src/iface/ethernet.rs | 22 ++++++++++------------ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index ce2a999..667c089 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -42,7 +42,7 @@ fn main() { let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 2), 24)]; let default_v4_gw = Ipv4Address::new(192, 168, 69, 100); let mut iface = EthernetInterface::new( - Box::new(device), Box::new(arp_cache) as Box, + device, Box::new(arp_cache) as Box, ethernet_addr, ip_addrs, Some(default_v4_gw)); let mut sockets = SocketSet::new(vec![]); diff --git a/examples/loopback.rs b/examples/loopback.rs index 9a8c68a..c263c6f 100644 --- a/examples/loopback.rs +++ b/examples/loopback.rs @@ -69,10 +69,10 @@ mod mock { fn main() { let clock = mock::Clock::new(); - let mut device = Loopback::new(); + let device = Loopback::new(); #[cfg(feature = "std")] - let mut device = { + let device = { let clock = clock.clone(); utils::setup_logging_with_clock("", move || clock.elapsed()); @@ -90,7 +90,7 @@ fn main() { let mut ip_addrs = [IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8)]; let mut iface = EthernetInterface::new( - &mut device, &mut arp_cache as &mut ArpCache, + device, &mut arp_cache as &mut ArpCache, EthernetAddress::default(), &mut ip_addrs[..], None); let server_socket = { diff --git a/examples/ping.rs b/examples/ping.rs index 032530c..ed40a71 100644 --- a/examples/ping.rs +++ b/examples/ping.rs @@ -60,7 +60,7 @@ fn main() { let ip_addr = IpCidr::new(IpAddress::from(local_addr), 24); let default_v4_gw = Ipv4Address::new(192, 168, 69, 100); let mut iface = EthernetInterface::new( - Box::new(device), Box::new(arp_cache) as Box, + device, Box::new(arp_cache) as Box, ethernet_addr, [ip_addr], Some(default_v4_gw)); let mut sockets = SocketSet::new(vec![]); diff --git a/examples/server.rs b/examples/server.rs index 3a62adb..70bcab4 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -56,7 +56,7 @@ fn main() { let ethernet_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]); let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24)]; let mut iface = EthernetInterface::new( - Box::new(device), Box::new(arp_cache) as Box, + device, Box::new(arp_cache) as Box, ethernet_addr, ip_addrs, None); let mut sockets = SocketSet::new(vec![]); diff --git a/src/iface/ethernet.rs b/src/iface/ethernet.rs index 30cfb52..67c0f4f 100644 --- a/src/iface/ethernet.rs +++ b/src/iface/ethernet.rs @@ -31,8 +31,8 @@ use super::ArpCache; /// The network interface logically owns a number of other data structures; to avoid /// a dependency on heap allocation, it instead owns a `BorrowMut<[T]>`, which can be /// a `&mut [T]`, or `Vec` if a heap is available. -pub struct Interface<'a, 'b, 'c, DeviceT: for<'d> Device<'d> + 'a> { - device: Managed<'a, DeviceT>, +pub struct Interface<'b, 'c, DeviceT: for<'d> Device<'d>> { + device: DeviceT, inner: InterfaceInner<'b, 'c>, } @@ -64,24 +64,22 @@ enum Packet<'a> { Tcp((IpRepr, TcpRepr<'a>)) } -impl<'a, 'b, 'c, DeviceT> Interface<'a, 'b, 'c, DeviceT> - where DeviceT: for<'d> Device<'d> + 'a { +impl<'b, 'c, DeviceT> Interface<'b, 'c, DeviceT> + where DeviceT: for<'d> Device<'d> { /// Create a network interface using the provided network device. /// /// # Panics /// See the restrictions on [set_hardware_addr](#method.set_hardware_addr) /// and [set_protocol_addrs](#method.set_protocol_addrs) functions. - pub fn new - (device: DeviceMT, arp_cache: ArpCacheMT, + pub fn new + (device: DeviceT, arp_cache: ArpCacheMT, ethernet_addr: EthernetAddress, ip_addrs: ProtocolAddrsMT, ipv4_gateway: Ipv4GatewayAddrT) -> - Interface<'a, 'b, 'c, DeviceT> - where DeviceMT: Into>, - ArpCacheMT: Into>, + Interface<'b, 'c, DeviceT> + where ArpCacheMT: Into>, ProtocolAddrsMT: Into>, Ipv4GatewayAddrT: Into>, { - let device = device.into(); let ip_addrs = ip_addrs.into(); InterfaceInner::check_ethernet_addr(ðernet_addr); InterfaceInner::check_ip_addrs(&ip_addrs); @@ -717,7 +715,7 @@ mod test { use {Result, Error}; fn create_loopback<'a, 'b>() -> - (EthernetInterface<'a, 'static, 'b, Loopback>, SocketSet<'static, 'a, 'b>) { + (EthernetInterface<'static, 'b, Loopback>, SocketSet<'static, 'a, 'b>) { // Create a basic device let device = Loopback::new(); @@ -725,7 +723,7 @@ mod test { let ip_addr = IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8); (EthernetInterface::new( - Box::new(device), Box::new(arp_cache) as Box, + device, Box::new(arp_cache) as Box, EthernetAddress::default(), [ip_addr], None), SocketSet::new(vec![])) }