Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7d838b6d9f0e
Choose a base ref
...
head repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 37f565abe2cd
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Dec 17, 2016

  1. Fix a Cargo warning.

    whitequark committed Dec 17, 2016
    Copy the full SHA
    ef04295 View commit details
  2. Fix lifetime variance.

    whitequark committed Dec 17, 2016
    Copy the full SHA
    37f565a View commit details
Showing with 28 additions and 29 deletions.
  1. +0 −1 Cargo.toml
  2. +8 −8 src/iface/ethernet.rs
  3. +2 −2 src/managed.rs
  4. +5 −5 src/socket/mod.rs
  5. +13 −13 src/socket/udp.rs
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ name = "smoltcp"
version = "0.1.0"
authors = ["whitequark <whitequark@whitequark.org>"]
license = "0BSD"
license-file = "LICENSE-0BSD"

[dependencies]
byteorder = { version = "0.5", default-features = false }
16 changes: 8 additions & 8 deletions src/iface/ethernet.rs
Original file line number Diff line number Diff line change
@@ -17,34 +17,34 @@ 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
/// See the restrictions on [set_hardware_addr](#method.set_hardware_addr)
/// 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()
}

4 changes: 2 additions & 2 deletions src/managed.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
10 changes: 5 additions & 5 deletions src/socket/mod.rs
Original file line number Diff line number Diff line change
@@ -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")
26 changes: 13 additions & 13 deletions src/socket/udp.rs
Original file line number Diff line number Diff line change
@@ -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,