Skip to main content

DoubleBufHelper

Struct DoubleBufHelper 

Source
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>

Source

pub fn new(buf: &'a [u8], buf2: &'a [u8]) -> Self

Source

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.

Source

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.

Source

pub fn get(&self) -> [&'a [u8]; 2]

Source

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.

Source

pub fn read_u8(&mut self) -> Option<u8>

Read 1 byte and advance. Returns 1

Source

pub fn get_contiguous(&self, len: usize) -> Option<&'a [u8]>

Get a contiguous slice at the start if it exists.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn with_max_len(&self, max_len: usize) -> DoubleBufHelper<'a>

Source

pub fn as_ioslices(&self, len_limit: usize) -> [IoSlice<'a>; 2]

Trait Implementations§

Source§

impl<'a> Clone for DoubleBufHelper<'a>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<'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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more