Struct smoltcp::storage::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§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.