Struct StructBuffer

Source
pub struct StructBuffer<M: StructLength> { /* private fields */ }
Expand description

A buffer that accumulates bytes of sized structs and feeds them to provided sink function when messages are complete. This buffer handles partial messages and multiple messages in a single push.

Implementations§

Source§

impl<M: StructLength> StructBuffer<M>

Source

pub fn push<'a: 'b, 'b>( &'b mut self, bytes: &'a [u8], f: impl for<'c> FnMut(Result<M::Struct<'c>, ParseError>), )

Pushes bytes into the buffer, potentially feeding output to the function.

§Lifetimes
  • 'a: The lifetime of the input byte slice.
  • 'b: The lifetime of the mutable reference to self.
  • 'c: A lifetime used in the closure’s type, representing the lifetime of the M::Struct instances passed to it.

The constraint 'a: 'b ensures that the input bytes live at least as long as the mutable reference to self.

The for<'c> syntax in the closure type is a higher-ranked trait bound. It indicates that the closure must be able to handle M::Struct with any lifetime 'c. This is crucial because:

  1. It allows the push method to create M::Struct instances with lifetimes that are not known at the time the closure is defined.
  2. It ensures that the M::Struct instances passed to the closure are only valid for the duration of each call to the closure, not for the entire lifetime of the push method.
  3. It prevents the closure from storing or returning these M::Struct instances, as their lifetime is limited to the scope of each closure invocation.
Source

pub fn push_fallible<'a: 'b, 'b, E>( &'b mut self, bytes: &'a [u8], f: impl for<'c> FnMut(Result<M::Struct<'c>, ParseError>) -> Result<(), E>, ) -> Result<(), E>

Pushes bytes into the buffer, potentially feeding output to the function.

§Lifetimes
  • 'a: The lifetime of the input byte slice.
  • 'b: The lifetime of the mutable reference to self.
  • 'c: A lifetime used in the closure’s type, representing the lifetime of the M::Struct instances passed to it.

The constraint 'a: 'b ensures that the input bytes live at least as long as the mutable reference to self.

The for<'c> syntax in the closure type is a higher-ranked trait bound. It indicates that the closure must be able to handle M::Struct with any lifetime 'c. This is crucial because:

  1. It allows the push method to create M::Struct instances with lifetimes that are not known at the time the closure is defined.
  2. It ensures that the M::Struct instances passed to the closure are only valid for the duration of each call to the closure, not for the entire lifetime of the push method.
  3. It prevents the closure from storing or returning these M::Struct instances, as their lifetime is limited to the scope of each closure invocation.
Source

pub fn into_inner(self) -> VecDeque<u8>

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl<M: StructLength> Debug for StructBuffer<M>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<M: StructLength> Default for StructBuffer<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<M> Freeze for StructBuffer<M>

§

impl<M> RefUnwindSafe for StructBuffer<M>
where M: RefUnwindSafe,

§

impl<M> Send for StructBuffer<M>
where M: Send,

§

impl<M> Sync for StructBuffer<M>
where M: Sync,

§

impl<M> Unpin for StructBuffer<M>
where M: Unpin,

§

impl<M> UnwindSafe for StructBuffer<M>
where M: UnwindSafe,

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.