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§
Implementations§
source§impl<T> MaybeParsed<T, T>
impl<T> MaybeParsed<T, T>
sourcepub fn new_with_min_len(bytes: T, min_len: usize) -> Selfwhere
T: ByteSlice,
pub fn new_with_min_len(bytes: T, min_len: usize) -> Selfwhere
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.
sourcepub fn into_inner(self) -> T
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>
impl<C, I> MaybeParsed<C, I>
sourcepub fn take_from_buffer_with<BV: BufferView<I>, F>(
buf: &mut BV,
n: usize,
map: F,
) -> Selfwhere
F: FnOnce(I) -> C,
I: ByteSlice,
pub fn take_from_buffer_with<BV: BufferView<I>, F>(
buf: &mut BV,
n: usize,
map: F,
) -> Selfwhere
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
.
sourcepub fn map<M, F>(self, f: F) -> MaybeParsed<M, I>where
F: FnOnce(C) -> M,
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.
sourcepub fn map_incomplete<M, F>(self, f: F) -> MaybeParsed<C, M>where
F: FnOnce(I) -> M,
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.
sourcepub fn as_ref(&self) -> MaybeParsed<&C, &I>
pub fn as_ref(&self) -> MaybeParsed<&C, &I>
Converts from &MaybeParsed<C, I>
to MaybeParsed<&C, &I>
.
sourcepub fn incomplete(self) -> Result<I, C>
pub fn incomplete(self) -> Result<I, C>
Transforms self
into a Result
, mapping the Incomplete
variant
into Ok
.
sourcepub fn ok_or_else<F, E>(self, f: F) -> Result<C, E>where
F: FnOnce(I) -> E,
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
.
Trait Implementations§
source§impl<C: Clone, I: Clone> Clone for MaybeParsed<C, I>
impl<C: Clone, I: Clone> Clone for MaybeParsed<C, I>
source§fn clone(&self) -> MaybeParsed<C, I>
fn clone(&self) -> MaybeParsed<C, I>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<C: PartialEq, I: PartialEq> PartialEq for MaybeParsed<C, I>
impl<C: PartialEq, I: PartialEq> PartialEq for MaybeParsed<C, I>
source§fn eq(&self, other: &MaybeParsed<C, I>) -> bool
fn eq(&self, other: &MaybeParsed<C, I>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<C: Copy, I: Copy> Copy for MaybeParsed<C, I>
impl<C: Eq, I: Eq> Eq for MaybeParsed<C, I>
impl<C, I> StructuralPartialEq for MaybeParsed<C, I>
Auto Trait Implementations§
impl<C, I> Freeze for MaybeParsed<C, I>
impl<C, I> RefUnwindSafe for MaybeParsed<C, I>where
C: RefUnwindSafe,
I: RefUnwindSafe,
impl<C, I> Send for MaybeParsed<C, I>
impl<C, I> Sync for MaybeParsed<C, I>
impl<C, I> Unpin for MaybeParsed<C, I>
impl<C, I> UnwindSafe for MaybeParsed<C, I>where
C: UnwindSafe,
I: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)