Enum packet::MaybeParsed

source ·
pub enum MaybeParsed<C, I> {
    Complete(C),
    Incomplete(I),
}
Expand description

A type that encapsulates the result of a complete or incomplete parsing operation.

The type parameters C and I are the types for a “complete” and “incomplete” parsing result, respectively.

Variants§

§

Complete(C)

§

Incomplete(I)

Implementations§

source§

impl<T> MaybeParsed<T, T>

source

pub fn new_with_min_len(bytes: T, min_len: usize) -> Self
where T: ByteSlice,

Creates a MaybeParsed instance with bytes observing a minimum length min_len.

Returns MaybeParsed::Complete if bytes is at least min_len long, otherwise returns MaybeParsed::Incomplete. In both cases, bytes is moved into one of the two MaybeParsed variants.

source

pub fn into_inner(self) -> T

Consumes this MaybeParsed and returns its contained value if both the Complete and Incomplete variants contain the same type.

source§

impl<C, I> MaybeParsed<C, I>

source

pub fn take_from_buffer_with<BV: BufferView<I>, F>( buf: &mut BV, n: usize, map: F, ) -> Self
where F: FnOnce(I) -> C, I: ByteSlice,

Creates a MaybeParsed instance taking n bytes from the front of buf and mapping with map.

If buf contains at least n bytes, then n bytes are consumed from the beginning of buf, those n bytes are passed to map, and the result is returned as MaybeParsed::Complete. Otherwise, all bytes are consumed from buf and returned as MaybeParsed::Incomplete.

source

pub fn map<M, F>(self, f: F) -> MaybeParsed<M, I>
where F: FnOnce(C) -> M,

Maps a MaybeParsed::Complete variant to another type.

If self is MaybeParsed::Incomplete, it is left as-is.

source

pub fn map_incomplete<M, F>(self, f: F) -> MaybeParsed<C, M>
where F: FnOnce(I) -> M,

Maps a MaybeParsed::Incomplete variant to another type.

If self is MaybeParsed::Complete, it is left as-is.

source

pub fn as_ref(&self) -> MaybeParsed<&C, &I>

Converts from &MaybeParsed<C, I> to MaybeParsed<&C, &I>.

source

pub fn complete(self) -> Result<C, I>

Transforms self into a Result, mapping the Complete variant into Ok.

source

pub fn incomplete(self) -> Result<I, C>

Transforms self into a Result, mapping the Incomplete variant into Ok.

source

pub fn ok_or_else<F, E>(self, f: F) -> Result<C, E>
where F: FnOnce(I) -> E,

Transforms this MaybeIncomplete into a Result where the Complete variant becomes Ok and the Incomplete variant is passed through f and mapped to Err.

source§

impl<C, I> MaybeParsed<C, I>
where C: Deref<Target = [u8]>, I: Deref<Target = [u8]>,

source

pub fn len(&self) -> usize

Returns the length in bytes of the contained data.

source

pub fn is_empty(&self) -> bool

Returns whether the contained data is empty - zero bytes long.

Trait Implementations§

source§

impl<C: Clone, I: Clone> Clone for MaybeParsed<C, I>

source§

fn clone(&self) -> MaybeParsed<C, I>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: Debug, I: Debug> Debug for MaybeParsed<C, I>

source§

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

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

impl<C: PartialEq, I: PartialEq> PartialEq for MaybeParsed<C, I>

source§

fn eq(&self, other: &MaybeParsed<C, I>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<C: Copy, I: Copy> Copy for MaybeParsed<C, I>

source§

impl<C: Eq, I: Eq> Eq for MaybeParsed<C, I>

source§

impl<C, I> StructuralPartialEq for MaybeParsed<C, I>

Auto Trait Implementations§

§

impl<C, I> Freeze for MaybeParsed<C, I>
where C: Freeze, I: Freeze,

§

impl<C, I> RefUnwindSafe for MaybeParsed<C, I>

§

impl<C, I> Send for MaybeParsed<C, I>
where C: Send, I: Send,

§

impl<C, I> Sync for MaybeParsed<C, I>
where C: Sync, I: Sync,

§

impl<C, I> Unpin for MaybeParsed<C, I>
where C: Unpin, I: Unpin,

§

impl<C, I> UnwindSafe for MaybeParsed<C, I>
where C: UnwindSafe, I: 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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.