pub struct StructBuffer<M>where
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> StructBuffer<M>where
M: StructLength,
impl<M> StructBuffer<M>where
M: StructLength,
Sourcepub fn push<'a, 'b>(
&'b mut self,
bytes: &'a [u8],
f: impl for<'c> FnMut(Result<<M as StructMeta>::Struct<'c>, ParseError>),
)where
'a: 'b,
pub fn push<'a, 'b>(
&'b mut self,
bytes: &'a [u8],
f: impl for<'c> FnMut(Result<<M as StructMeta>::Struct<'c>, ParseError>),
)where
'a: 'b,
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 toself
.'c
: A lifetime used in the closure’s type, representing the lifetime of theM::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:
- It allows the
push
method to createM::Struct
instances with lifetimes that are not known at the time the closure is defined. - 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 thepush
method. - It prevents the closure from storing or returning these
M::Struct
instances, as their lifetime is limited to the scope of each closure invocation.
Sourcepub fn push_fallible<'a, 'b, E>(
&'b mut self,
bytes: &'a [u8],
f: impl for<'c> FnMut(Result<<M as StructMeta>::Struct<'c>, ParseError>) -> Result<(), E>,
) -> Result<(), E>where
'a: 'b,
pub fn push_fallible<'a, 'b, E>(
&'b mut self,
bytes: &'a [u8],
f: impl for<'c> FnMut(Result<<M as StructMeta>::Struct<'c>, ParseError>) -> Result<(), E>,
) -> Result<(), E>where
'a: 'b,
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 toself
.'c
: A lifetime used in the closure’s type, representing the lifetime of theM::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:
- It allows the
push
method to createM::Struct
instances with lifetimes that are not known at the time the closure is defined. - 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 thepush
method. - It prevents the closure from storing or returning these
M::Struct
instances, as their lifetime is limited to the scope of each closure invocation.