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