Enum packet::serialize::Either

source ·
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§

§

A(A)

§

B(B)

Implementations§

source§

impl<A, B> Either<A, B>

source

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.

source

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

pub fn unwrap_a(self) -> A

Returns the A variant in an Either<A, B>.

§Panics

Panics if this Either<A, B> does not hold the A variant.

source

pub fn unwrap_b(self) -> B

Returns the B variant in an Either<A, B>.

§Panics

Panics if this Either<A, B> does not hold the B variant.

source§

impl<A> Either<A, A>

source

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>

source

pub fn into_a(self) -> A

Returns the A value in an Either<A, Never>.

source§

impl<B> Either<Infallible, B>

source

pub fn into_b(self) -> B

Returns the B value in an Either<Never, B>.

Trait Implementations§

source§

impl<A: AsMut<[u8]>, B: AsMut<[u8]>> AsMut<[u8]> for Either<A, B>

source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<A: AsRef<[u8]>, B: AsRef<[u8]>> AsRef<[u8]> for Either<A, B>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<A, B> Buffer for Either<A, B>
where A: Buffer, B: Buffer,

source§

fn parse_with_view<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>( &'a mut self, args: ParseArgs ) -> Result<(P, &'a [u8]), P::Error>

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

source§

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

The type of errors returned from reuse_or_realloc.
source§

fn alloc_no_reuse( self, prefix: usize, body: usize, suffix: usize ) -> Result<Either<I, O>, Self::Error>

Attempts to produce an output buffer with the given constraints by allocating a new one. Read more
source§

impl<A: Clone, B: Clone> Clone for Either<A, B>

source§

fn clone(&self) -> Either<A, B>

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<A: Debug, B: Debug> Debug for Either<A, B>

source§

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

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

impl<A, B> FragmentedBuffer for Either<A, B>

source§

fn len(&self) -> usize

Gets the total length, in bytes, of this FragmentedBuffer.
source§

fn with_bytes<R, F>(&self, f: F) -> R
where F: for<'a, 'b> FnOnce(FragmentedBytes<'a, 'b>) -> R,

Invokes a callback on a view into this buffer’s contents as FragmentedBytes.
source§

fn is_empty(&self) -> bool

Returns true if this FragmentedBuffer is empty.
source§

fn to_flattened_vec(&self) -> Vec<u8>

Returns a flattened version of this buffer, copying its contents into a Vec.
source§

impl<A, B> FragmentedBufferMut for Either<A, B>

source§

fn with_bytes_mut<R, F>(&mut self, f: F) -> R
where F: for<'a, 'b> FnOnce(FragmentedBytesMut<'a, 'b>) -> R,

Invokes a callback on a mutable view into this buffer’s contents as FragmentedBytesMut.
source§

fn zero_range<R>(&mut self, range: R)
where R: RangeBounds<usize>,

Sets all bytes in range to zero. Read more
source§

fn copy_within<R: RangeBounds<usize>>(&mut self, src: R, dst: usize)

Copies elements from one part of the FragmentedBufferMut to another part of itself. Read more
source§

fn copy_from<B: FragmentedBuffer>(&mut self, other: &B)

Copies all the bytes from another FragmentedBuffer other into self. Read more
source§

impl<A, B> GrowBuffer for Either<A, B>
where A: GrowBuffer, B: GrowBuffer,

source§

fn with_parts<O, F>(&self, f: F) -> O
where F: for<'a, 'b> FnOnce(&'a [u8], FragmentedBytes<'a, 'b>, &'a [u8]) -> O,

Gets a view into the parts of this GrowBuffer. Read more
source§

fn capacity(&self) -> usize

The capacity of the buffer. Read more
source§

fn prefix_len(&self) -> usize

The length of the prefix.
source§

fn suffix_len(&self) -> usize

The length of the suffix.
source§

fn grow_front(&mut self, n: usize)

Grows the front of the body towards Growf the buffer. Read more
source§

fn grow_back(&mut self, n: usize)

Grows the back of the body towards the end of the buffer. Read more
source§

fn reset(&mut self)

Resets the body to be equal to the entire buffer. Read more
source§

fn undo_parse(&mut self, meta: ParseMetadata)

Undoes the effects of a previous parse in preparation for serialization. Read more
source§

impl<A, B> GrowBufferMut for Either<A, B>

source§

fn with_parts_mut<O, F>(&mut self, f: F) -> O
where F: for<'a, 'b> FnOnce(&'a mut [u8], FragmentedBytesMut<'a, 'b>, &'a mut [u8]) -> O,

Gets a mutable view into the parts of this GrowBufferMut. Read more
source§

fn grow_front_zero(&mut self, n: usize)

Extends the front of the body towards the beginning of the buffer, zeroing the new bytes. Read more
source§

fn grow_back_zero(&mut self, n: usize)

Extends the back of the body towards the end of the buffer, zeroing the new bytes. Read more
source§

fn reset_zero(&mut self)

Resets the body to be equal to the entire buffer, zeroing the new bytes. Read more
source§

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>

Parses a packet from the body. Read more
source§

fn parse_with<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>( &'a mut self, args: ParseArgs ) -> Result<P, P::Error>

Parses a packet with arguments. Read more
source§

impl<A, B> ParseBufferMut for Either<A, B>

source§

fn parse_mut<'a, P: ParsablePacket<&'a mut [u8], ()>>( &'a mut self ) -> Result<P, P::Error>

Parses a mutable packet from the body. Read more
source§

fn parse_with_mut<'a, ParseArgs, P: ParsablePacket<&'a mut [u8], ParseArgs>>( &'a mut self, args: ParseArgs ) -> Result<P, P::Error>

Parses a mutable packet with arguments. Read more
source§

impl<A, B> ShrinkBuffer for Either<A, B>

source§

fn shrink<R: RangeBounds<usize>>(&mut self, range: R)

Shrinks the body. Read more
source§

fn shrink_front(&mut self, n: usize)

Shrinks the front of the body towards the end of the buffer. Read more
source§

fn shrink_back(&mut self, n: usize)

Shrinks the back of the body towards the beginning of the buffer. Read more
source§

fn shrink_front_to(&mut self, len: usize)

Shrinks the buffer to be no larger than len bytes, consuming from the front. Read more
source§

fn shrink_back_to(&mut self, len: usize)

Shrinks the buffer to be no larger than len bytes, consuming from the back. Read more
source§

impl<A, B> ContiguousBuffer for Either<A, B>

source§

impl<A: Copy, B: Copy> Copy for Either<A, B>

Auto Trait Implementations§

§

impl<A, B> RefUnwindSafe for Either<A, B>

§

impl<A, B> Send for Either<A, B>
where A: Send, B: Send,

§

impl<A, B> Sync for Either<A, B>
where A: Sync, B: Sync,

§

impl<A, B> Unpin for Either<A, B>
where A: Unpin, B: Unpin,

§

impl<A, B> UnwindSafe for Either<A, B>
where A: UnwindSafe, B: 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<O, B> AsFragmentedByteSlice<B> for O
where B: Fragment, O: AsMut<[B]>,

source§

fn as_fragmented_byte_slice(&mut self) -> FragmentedByteSlice<'_, B>

Generates a FragmentedByteSlice view of self.
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> 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<B> Serializer for B

§

type Buffer = B

The type of buffers returned from serialization methods on this trait.
source§

fn serialize<BB, P>( self, outer: PacketConstraints, provider: P ) -> Result<BB, (SerializeError<<P as BufferProvider<<B as Serializer>::Buffer, BB>>::Error>, B)>
where BB: GrowBufferMut, P: BufferProvider<<B as Serializer>::Buffer, BB>,

Serializes this Serializer, producing a buffer. Read more
source§

fn serialize_vec( self, outer: PacketConstraints ) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>
where Self::Buffer: ReusableBuffer,

Serializes this Serializer, allocating a Buf<Vec<u8>> if the contained buffer isn’t large enough. Read more
source§

fn serialize_no_alloc( self, outer: PacketConstraints ) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>
where Self::Buffer: ReusableBuffer,

Serializes this Serializer, failing if the existing buffer is not large enough. Read more
source§

fn serialize_outer<B: GrowBufferMut, P: BufferProvider<Self::Buffer, B>>( self, provider: P ) -> Result<B, (SerializeError<P::Error>, Self)>

Serializes this Serializer as the outermost packet. Read more
source§

fn serialize_vec_outer( self ) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>
where Self::Buffer: ReusableBuffer,

Serializes this Serializer as the outermost packet, allocating a Buf<Vec<u8>> if the contained buffer isn’t large enough. Read more
source§

fn serialize_no_alloc_outer( self ) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>
where Self::Buffer: ReusableBuffer,

Serializes this Serializer as the outermost packet, failing if the existing buffer is not large enough. Read more
source§

fn encapsulate<B>(self, outer: B) -> Nested<Self, B>

Encapsulates this Serializer in another packet, producing a new Serializer. Read more
source§

fn with_size_limit(self, limit: usize) -> Nested<Self, LimitedSizePacketBuilder>

Creates a new Serializer which will enforce a size limit. Read more
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.
source§

impl<B> BufferMut for B

source§

impl<B> ContiguousBufferMut for B

source§

impl<B> ReusableBuffer for B