pub enum Either<A, B> {
A(A),
B(B),
}
Expand description
Either of two buffers.
An Either
wraps one of two different buffer types. It implements all of
the relevant traits by calling the corresponding methods on the wrapped
buffer.
Variants§
Implementations§
source§impl<A, B> Either<A, B>
impl<A, B> Either<A, B>
sourcepub fn map_a<AA, F: FnOnce(A) -> AA>(self, f: F) -> Either<AA, B>
pub fn map_a<AA, F: FnOnce(A) -> AA>(self, f: F) -> Either<AA, B>
Maps the A
variant of an Either
.
Given an Either<A, B>
and a function from A
to AA
, map_a
produces an Either<AA, B>
by applying the function to the A
variant
or passing on the B
variant unmodified.
sourcepub fn map_b<BB, F: FnOnce(B) -> BB>(self, f: F) -> Either<A, BB>
pub fn map_b<BB, F: FnOnce(B) -> BB>(self, f: F) -> Either<A, BB>
Maps the B
variant of an Either
.
Given an Either<A, B>
and a function from B
to BB
, map_b
produces an Either<A, BB>
by applying the function to the B
variant
or passing on the A
variant unmodified.
source§impl<A> Either<A, A>
impl<A> Either<A, A>
sourcepub fn into_inner(self) -> A
pub fn into_inner(self) -> A
Returns the inner value held by this Either
when both possible values
Either::A
and Either::B
contain the same inner types.
source§impl<A> Either<A, Infallible>
impl<A> Either<A, Infallible>
Trait Implementations§
source§impl<A, B> Buffer for Either<A, B>
impl<A, B> Buffer for Either<A, B>
source§fn parse_with_view<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>(
&'a mut self,
args: ParseArgs,
) -> Result<(P, &'a [u8]), P::Error>
fn parse_with_view<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>( &'a mut self, args: ParseArgs, ) -> Result<(P, &'a [u8]), P::Error>
ParseBuffer::parse_with
but additionally provides an
un-structured view into the parsed data on successful parsing.source§impl<I: ReusableBuffer, O: ReusableBuffer, A: BufferAlloc<O>> BufferProvider<I, Either<I, O>> for MaybeReuseBufferProvider<A>
impl<I: ReusableBuffer, O: ReusableBuffer, A: BufferAlloc<O>> BufferProvider<I, Either<I, O>> for MaybeReuseBufferProvider<A>
source§fn reuse_or_realloc(
self,
buffer: I,
need_prefix: usize,
need_suffix: usize,
) -> Result<Either<I, O>, (A::Error, I)>
fn reuse_or_realloc( self, buffer: I, need_prefix: usize, need_suffix: usize, ) -> Result<Either<I, O>, (A::Error, I)>
If buffer
has enough capacity to store need_prefix + need_suffix + buffer.len()
bytes, then reuse buffer
. Otherwise, allocate a new
buffer using A
’s BufferAlloc
implementation.
If there is enough capacity, but the body is too far forwards or backwards in the buffer to satisfy the prefix and suffix constraints, the body will be moved within the buffer in order to satisfy the constraints. This operation is linear in the length of the body.
§type Error = <A as BufferAlloc<O>>::Error
type Error = <A as BufferAlloc<O>>::Error
reuse_or_realloc
.source§impl<A, B> FragmentedBuffer for Either<A, B>where
A: FragmentedBuffer,
B: FragmentedBuffer,
impl<A, B> FragmentedBuffer for Either<A, B>where
A: FragmentedBuffer,
B: FragmentedBuffer,
source§fn with_bytes<R, F>(&self, f: F) -> Rwhere
F: for<'a, 'b> FnOnce(FragmentedBytes<'a, 'b>) -> R,
fn with_bytes<R, F>(&self, f: F) -> Rwhere
F: for<'a, 'b> FnOnce(FragmentedBytes<'a, 'b>) -> R,
FragmentedBytes
.source§impl<A, B> FragmentedBufferMut for Either<A, B>where
A: FragmentedBufferMut,
B: FragmentedBufferMut,
impl<A, B> FragmentedBufferMut for Either<A, B>where
A: FragmentedBufferMut,
B: FragmentedBufferMut,
source§fn with_bytes_mut<R, F>(&mut self, f: F) -> Rwhere
F: for<'a, 'b> FnOnce(FragmentedBytesMut<'a, 'b>) -> R,
fn with_bytes_mut<R, F>(&mut self, f: F) -> Rwhere
F: for<'a, 'b> FnOnce(FragmentedBytesMut<'a, 'b>) -> R,
FragmentedBytesMut
.source§fn zero_range<R>(&mut self, range: R)where
R: RangeBounds<usize>,
fn zero_range<R>(&mut self, range: R)where
R: RangeBounds<usize>,
range
to zero. Read moresource§fn copy_within<R: RangeBounds<usize>>(&mut self, src: R, dst: usize)
fn copy_within<R: RangeBounds<usize>>(&mut self, src: R, dst: usize)
FragmentedBufferMut
to another
part of itself. Read moresource§impl<A, B> GrowBuffer for Either<A, B>where
A: GrowBuffer,
B: GrowBuffer,
impl<A, B> GrowBuffer for Either<A, B>where
A: GrowBuffer,
B: GrowBuffer,
source§fn with_parts<O, F>(&self, f: F) -> O
fn with_parts<O, F>(&self, f: F) -> O
GrowBuffer
. Read moresource§fn prefix_len(&self) -> usize
fn prefix_len(&self) -> usize
source§fn suffix_len(&self) -> usize
fn suffix_len(&self) -> usize
source§fn grow_front(&mut self, n: usize)
fn grow_front(&mut self, n: usize)
source§fn grow_back(&mut self, n: usize)
fn grow_back(&mut self, n: usize)
source§fn undo_parse(&mut self, meta: ParseMetadata)
fn undo_parse(&mut self, meta: ParseMetadata)
source§impl<A, B> GrowBufferMut for Either<A, B>where
A: GrowBufferMut,
B: GrowBufferMut,
impl<A, B> GrowBufferMut for Either<A, B>where
A: GrowBufferMut,
B: GrowBufferMut,
source§fn with_parts_mut<O, F>(&mut self, f: F) -> O
fn with_parts_mut<O, F>(&mut self, f: F) -> O
GrowBufferMut
. Read moresource§fn with_header_mut_with_meta<O, F>(&mut self, meta: ParseMetadata, f: F) -> O
fn with_header_mut_with_meta<O, F>(&mut self, meta: ParseMetadata, f: F) -> O
source§fn grow_front_zero(&mut self, n: usize)
fn grow_front_zero(&mut self, n: usize)
source§fn grow_back_zero(&mut self, n: usize)
fn grow_back_zero(&mut self, n: usize)
source§fn reset_zero(&mut self)
fn reset_zero(&mut self)
source§impl<A, B> ParseBuffer for Either<A, B>where
A: ParseBuffer,
B: ParseBuffer,
impl<A, B> ParseBuffer for Either<A, B>where
A: ParseBuffer,
B: ParseBuffer,
source§fn parse<'a, P: ParsablePacket<&'a [u8], ()>>(
&'a mut self,
) -> Result<P, P::Error>
fn parse<'a, P: ParsablePacket<&'a [u8], ()>>( &'a mut self, ) -> Result<P, P::Error>
source§fn parse_with<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>(
&'a mut self,
args: ParseArgs,
) -> Result<P, P::Error>
fn parse_with<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>( &'a mut self, args: ParseArgs, ) -> Result<P, P::Error>
source§impl<A, B> ParseBufferMut for Either<A, B>where
A: ParseBufferMut,
B: ParseBufferMut,
impl<A, B> ParseBufferMut for Either<A, B>where
A: ParseBufferMut,
B: ParseBufferMut,
source§fn parse_mut<'a, P: ParsablePacket<&'a mut [u8], ()>>(
&'a mut self,
) -> Result<P, P::Error>
fn parse_mut<'a, P: ParsablePacket<&'a mut [u8], ()>>( &'a mut self, ) -> Result<P, P::Error>
source§fn parse_with_mut<'a, ParseArgs, P: ParsablePacket<&'a mut [u8], ParseArgs>>(
&'a mut self,
args: ParseArgs,
) -> Result<P, P::Error>
fn parse_with_mut<'a, ParseArgs, P: ParsablePacket<&'a mut [u8], ParseArgs>>( &'a mut self, args: ParseArgs, ) -> Result<P, P::Error>
source§impl<A, B> ShrinkBuffer for Either<A, B>where
A: ShrinkBuffer,
B: ShrinkBuffer,
impl<A, B> ShrinkBuffer for Either<A, B>where
A: ShrinkBuffer,
B: ShrinkBuffer,
source§fn shrink_front(&mut self, n: usize)
fn shrink_front(&mut self, n: usize)
source§fn shrink_back(&mut self, n: usize)
fn shrink_back(&mut self, n: usize)
source§fn shrink_front_to(&mut self, len: usize)
fn shrink_front_to(&mut self, len: usize)
len
bytes, consuming from the
front. Read moresource§fn shrink_back_to(&mut self, len: usize)
fn shrink_back_to(&mut self, len: usize)
len
bytes, consuming from the
back. Read moreimpl<A, B> ContiguousBuffer for Either<A, B>where
A: ContiguousBuffer,
B: ContiguousBuffer,
impl<A: Copy, B: Copy> Copy for Either<A, B>
Auto Trait Implementations§
impl<A, B> Freeze for Either<A, B>
impl<A, B> RefUnwindSafe for Either<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Either<A, B>
impl<A, B> Sync for Either<A, B>
impl<A, B> Unpin for Either<A, B>
impl<A, B> UnwindSafe for Either<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
source§impl<O, B> AsFragmentedByteSlice<B> for O
impl<O, B> AsFragmentedByteSlice<B> for O
source§fn as_fragmented_byte_slice(&mut self) -> FragmentedByteSlice<'_, B>
fn as_fragmented_byte_slice(&mut self) -> FragmentedByteSlice<'_, B>
FragmentedByteSlice
view of self
.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
)source§impl<B> Serializer for Bwhere
B: GrowBuffer + ShrinkBuffer,
impl<B> Serializer for Bwhere
B: GrowBuffer + ShrinkBuffer,
source§fn serialize<BB, P>(
self,
outer: PacketConstraints,
provider: P,
) -> Result<BB, (SerializeError<<P as BufferProvider<<B as Serializer>::Buffer, BB>>::Error>, B)>
fn serialize<BB, P>( self, outer: PacketConstraints, provider: P, ) -> Result<BB, (SerializeError<<P as BufferProvider<<B as Serializer>::Buffer, BB>>::Error>, B)>
Serializer
, producing a buffer. Read moresource§fn serialize_new_buf<BB, A>(
&self,
outer: PacketConstraints,
alloc: A,
) -> Result<BB, SerializeError<<A as BufferAlloc<BB>>::Error>>where
BB: ReusableBuffer,
A: BufferAlloc<BB>,
fn serialize_new_buf<BB, A>(
&self,
outer: PacketConstraints,
alloc: A,
) -> Result<BB, SerializeError<<A as BufferAlloc<BB>>::Error>>where
BB: ReusableBuffer,
A: BufferAlloc<BB>,
self
. Read moresource§fn serialize_vec(
self,
outer: PacketConstraints,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_vec(
self,
outer: PacketConstraints,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
Serializer
, allocating a Buf<Vec<u8>>
if the
contained buffer isn’t large enough. Read moresource§fn serialize_no_alloc(
self,
outer: PacketConstraints,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_no_alloc(
self,
outer: PacketConstraints,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
Serializer
, failing if the existing buffer is not
large enough. Read moresource§fn serialize_outer<B: GrowBufferMut, P: BufferProvider<Self::Buffer, B>>(
self,
provider: P,
) -> Result<B, (SerializeError<P::Error>, Self)>
fn serialize_outer<B: GrowBufferMut, P: BufferProvider<Self::Buffer, B>>( self, provider: P, ) -> Result<B, (SerializeError<P::Error>, Self)>
Serializer
as the outermost packet. Read moresource§fn serialize_vec_outer(
self,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_vec_outer(
self,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
Serializer
as the outermost packet, allocating a
Buf<Vec<u8>>
if the contained buffer isn’t large enough. Read moresource§fn serialize_no_alloc_outer(
self,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_no_alloc_outer(
self,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
Serializer
as the outermost packet, failing if the
existing buffer is not large enough. Read moresource§fn encapsulate<B>(self, outer: B) -> Nested<Self, B>
fn encapsulate<B>(self, outer: B) -> Nested<Self, B>
source§fn with_size_limit(self, limit: usize) -> Nested<Self, LimitedSizePacketBuilder>
fn with_size_limit(self, limit: usize) -> Nested<Self, LimitedSizePacketBuilder>
Serializer
which will enforce a size limit. Read more