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: SplitByteSlice,
pub fn new_with_min_len(bytes: T, min_len: usize) -> Selfwhere
T: SplitByteSlice,
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: SplitByteSlice,
pub fn take_from_buffer_with<BV: BufferView<I>, F>(
buf: &mut BV,
n: usize,
map: F,
) -> Selfwhere
F: FnOnce(I) -> C,
I: SplitByteSlice,
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 moreimpl<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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)