smoltcp::storage

Struct PacketBuffer

Source
pub struct PacketBuffer<'a, H: 'a> { /* private fields */ }
Expand description

An UDP packet ring buffer.

Implementations§

Source§

impl<'a, H> PacketBuffer<'a, H>

Source

pub fn new<MS, PS>( metadata_storage: MS, payload_storage: PS, ) -> PacketBuffer<'a, H>
where MS: Into<ManagedSlice<'a, PacketMetadata<H>>>, PS: Into<ManagedSlice<'a, u8>>,

Create a new packet buffer with the provided metadata and payload storage.

Metadata storage limits the maximum number of packets in the buffer and payload storage limits the maximum total size of packets.

Source

pub fn is_empty(&self) -> bool

Query whether the buffer is empty.

Source

pub fn is_full(&self) -> bool

Query whether the buffer is full.

Source

pub fn enqueue(&mut self, size: usize, header: H) -> Result<&mut [u8], Full>

Enqueue a single packet with the given header into the buffer, and return a reference to its payload, or return Err(Full) if the buffer is full.

Source

pub fn enqueue_with_infallible<'b, F>( &'b mut self, max_size: usize, header: H, f: F, ) -> Result<usize, Full>
where F: FnOnce(&'b mut [u8]) -> usize,

Call f with a packet from the buffer large enough to fit max_size bytes. The packet is shrunk to the size returned from f and enqueued into the buffer.

Source

pub fn dequeue_with<'c, R, E, F>( &'c mut self, f: F, ) -> Result<Result<R, E>, Empty>
where F: FnOnce(&mut H, &'c mut [u8]) -> Result<R, E>,

Call f with a single packet from the buffer, and dequeue the packet if f returns successfully, or return Err(EmptyError) if the buffer is empty.

Source

pub fn dequeue(&mut self) -> Result<(H, &mut [u8]), Empty>

Dequeue a single packet from the buffer, and return a reference to its payload as well as its header, or return Err(Error::Exhausted) if the buffer is empty.

Source

pub fn peek(&mut self) -> Result<(&H, &[u8]), Empty>

Peek at a single packet from the buffer without removing it, and return a reference to its payload as well as its header, or return Err(Error:Exhausted) if the buffer is empty.

This function otherwise behaves identically to dequeue.

Source

pub fn packet_capacity(&self) -> usize

Return the maximum number packets that can be stored.

Source

pub fn payload_capacity(&self) -> usize

Return the maximum number of bytes in the payload ring buffer.

Trait Implementations§

Source§

impl<'a, H: Debug + 'a> Debug for PacketBuffer<'a, H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, H> Freeze for PacketBuffer<'a, H>

§

impl<'a, H> RefUnwindSafe for PacketBuffer<'a, H>
where H: RefUnwindSafe,

§

impl<'a, H> Send for PacketBuffer<'a, H>
where H: Send,

§

impl<'a, H> Sync for PacketBuffer<'a, H>
where H: Sync,

§

impl<'a, H> Unpin for PacketBuffer<'a, H>
where H: Unpin,

§

impl<'a, H> !UnwindSafe for PacketBuffer<'a, H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.