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> 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 Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.