pub struct DoubleBufHelper<'a> { /* private fields */ }Expand description
A helper for working with a buffer split into 2. You can advance it forward (like you would do with buf=&buf[idx..])
Implementations§
Source§impl<'a> DoubleBufHelper<'a>
impl<'a> DoubleBufHelper<'a>
pub fn new(buf: &'a [u8], buf2: &'a [u8]) -> Self
Sourcepub fn consume_variable(
&mut self,
len: usize,
) -> Result<(&'a [u8], &'a [u8]), usize>
pub fn consume_variable( &mut self, len: usize, ) -> Result<(&'a [u8], &'a [u8]), usize>
Consume len bytes and return them as 2 slices. Advances the buffer forward if successful. On error returns how many bytes are missing.
Sourcepub fn consume<const N: usize>(&mut self) -> Result<[u8; N], usize>
pub fn consume<const N: usize>(&mut self) -> Result<[u8; N], usize>
Read N bytes and advance the buffer by N if successful. Error returns how many missing bytes are there.
pub fn get(&self) -> [&'a [u8]; 2]
Sourcepub fn read_u32_be(&mut self) -> Result<u32, usize>
pub fn read_u32_be(&mut self) -> Result<u32, usize>
Read 4 big endian bytes and advance the buffer by 4 if successful. Error returns how many missing bytes are there.
Sourcepub fn get_contiguous(&self, len: usize) -> Option<&'a [u8]>
pub fn get_contiguous(&self, len: usize) -> Option<&'a [u8]>
Get a contiguous slice at the start if it exists.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn advance(&mut self, offset: usize)
pub fn advance(&mut self, offset: usize)
Advance it forward. If it was a single buffer this would be equivalent to buf=&buf[idx..]). If offset is too large, will set itself empty.
pub fn with_max_len(&self, max_len: usize) -> DoubleBufHelper<'a>
pub fn as_ioslices(&self, len_limit: usize) -> [IoSlice<'a>; 2]
Trait Implementations§
Source§impl<'a> Clone for DoubleBufHelper<'a>
impl<'a> Clone for DoubleBufHelper<'a>
Source§fn clone(&self) -> DoubleBufHelper<'a>
fn clone(&self) -> DoubleBufHelper<'a>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<'a> Copy for DoubleBufHelper<'a>
Auto Trait Implementations§
impl<'a> Freeze for DoubleBufHelper<'a>
impl<'a> RefUnwindSafe for DoubleBufHelper<'a>
impl<'a> Send for DoubleBufHelper<'a>
impl<'a> Sync for DoubleBufHelper<'a>
impl<'a> Unpin for DoubleBufHelper<'a>
impl<'a> UnsafeUnpin for DoubleBufHelper<'a>
impl<'a> UnwindSafe for DoubleBufHelper<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more