Enum BoxedHeader

Source
pub enum BoxedHeader<O, B> {
    Repr(Box<O>),
    Raw(B),
}
Expand description

A header which is either owned or read from a buffer, which heap-allocates if the data is owned.

Generally, use of boxed Repr values reduces output struct sizes when parsing full packets and is preferred when compiling with the alloc feature. See InlineHeader if stack allocation is needed.

Variants§

§

Repr(Box<O>)

Owned, in-memory representation of a header.

§

Raw(B)

Packed representation of a header, read from an existing buffer.

Implementations§

Source§

impl<O, B> BoxedHeader<O, B>

Source

pub fn repr(&self) -> Option<&O>

Return a reference to this packet’s contents if they are owned.

Source

pub fn repr_mut(&mut self) -> Option<&mut O>

Return a mutable reference to this packet’s contents if they are owned.

Source

pub fn raw(&self) -> Option<&B>

Return a reference to this packet’s contents if they are borrowed.

Source

pub fn raw_mut(&mut self) -> Option<&mut B>

Return a mutable reference to this packet’s contents if they are borrowed.

Trait Implementations§

Source§

impl<O: Clone, B: Clone> Clone for BoxedHeader<O, B>

Source§

fn clone(&self) -> BoxedHeader<O, B>

Returns a duplicate 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<O: Debug, B: Debug> Debug for BoxedHeader<O, B>

Source§

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

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

impl<O: Emit, B: Emit> Emit for BoxedHeader<O, B>

Source§

fn emit_raw<V: ByteSliceMut>(&self, buf: V) -> usize

Writes this packet’s contents into a target buffer without performing length checks. Read more
Source§

fn needs_emit(&self) -> bool

Returns whether this packet needs a full re-emit, and has not been simply modified in-place. Read more
Source§

fn emit<V: ByteSliceMut>(&self, buf: V) -> ParseResult<usize>

Writes this packet’s contents into a target buffer.
Source§

fn emit_prefix<V: SplitByteSliceMut>(&self, buf: V) -> ParseResult<V>

Writes this packet’s contents into the start of a target buffer.
Source§

fn emit_suffix<V: SplitByteSliceMut>(&self, buf: V) -> ParseResult<V>

Writes this packet’s contents at the end of a target buffer.
Source§

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

Writes this packet’s contents into a newly allocated Vec of length Header::packet_length. Read more
Source§

fn emit_uninit(&self, buf: &mut [MaybeUninit<u8>]) -> ParseResult<usize>

Writes this packet’s contents into uninitialised memory.
Source§

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

Writes this packet’s contents into a newly allocated Vec of length Header::packet_length, without zero-filling the contents. Read more
Source§

impl<'a, T: HasView<V>, V> From<&'a BoxedHeader<T, <T as HasView<V>>::ViewType>> for FieldRef<'a, T, V>

Source§

fn from(value: &'a BoxedHeader<T, <T as HasView<V>>::ViewType>) -> Self

Converts to this type from the input type.
Source§

impl<B: ByteSlice, T> From<&BoxedHeader<Vec<T>, ObjectSlice<B, T>>> for Vec<T>

Source§

fn from(value: &Header<Vec<T>, ObjectSlice<B, T>>) -> Self

Converts to this type from the input type.
Source§

impl<B: ByteSlice, T> From<&BoxedHeader<Vec<T>, RawBytes<B>>> for Vec<T>

Source§

fn from(value: &Header<Vec<T>, RawBytes<B>>) -> Self

Converts to this type from the input type.
Source§

impl<V: ByteSlice> From<&BoxedHeader<Vec<u8>, V>> for Vec<u8>

Source§

fn from(value: &VarBytes<V>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: HasView<V>, V> From<&'a mut BoxedHeader<T, <T as HasView<V>>::ViewType>> for FieldMut<'a, T, V>

Source§

fn from(value: &'a mut BoxedHeader<T, <T as HasView<V>>::ViewType>) -> Self

Converts to this type from the input type.
Source§

impl<O, B> From<BoxedHeader<O, B>> for InlineHeader<O, B>

Source§

fn from(value: BoxedHeader<O, B>) -> Self

Converts to this type from the input type.
Source§

impl<O, B> From<InlineHeader<O, B>> for BoxedHeader<O, B>

Source§

fn from(value: InlineHeader<O, B>) -> Self

Converts to this type from the input type.
Source§

impl<O, B> HasRepr for BoxedHeader<O, B>

Source§

type ReprType = O

The type containing an equivalent to Self, as an owned struct.
Source§

impl<O: HasView<V, ViewType = B>, B, V> HasView<V> for BoxedHeader<O, B>

Source§

type ViewType = B

The type containing an equivalent to Self, as a network packet in a buffer B.
Source§

impl<O: Hash, B: Hash> Hash for BoxedHeader<O, B>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<O, B> HeaderLen for BoxedHeader<O, B>
where O: HeaderLen, B: HeaderLen,

Source§

const MINIMUM_LENGTH: usize = O::MINIMUM_LENGTH

The minimum number of bytes a packet of this kind occupies when serialised.
Source§

fn packet_length(&self) -> usize

The number of bytes which this packet would occupy when serialised. Read more
Source§

impl<V: SplitByteSlice, B> HeaderParse<V> for BoxedHeader<B::ReprType, B>
where B: NextLayer + HeaderParse<V> + HasRepr + Into<Self>, B::ReprType: NextLayer<Denom = B::Denom, Hint = B::Hint>,

Source§

fn parse_choice( from: V, hint: Option<Self::Hint>, ) -> ParseResult<Success<Self, V>>

Parse a view-type from a given buffer, using a hint
Source§

fn parse(from: B) -> ParseResult<Success<Self, B>>

Parse a view-type from a given buffer.
Source§

impl<O: NextLayer, B> NextLayer for BoxedHeader<O, B>
where B: NextLayer<Denom = O::Denom, Hint = O::Hint>,

Source§

type Denom = <O as NextLayer>::Denom

The type of this header’s next-layer hint.
Source§

type Hint = <O as NextLayer>::Hint

A type used to help parse the header
Source§

fn next_layer_choice(&self, hint: Option<Self::Hint>) -> Option<Self::Denom>

Try to retrieve this header’s next-layer hint, using a provided hint
Source§

fn next_layer(&self) -> Option<Self::Denom>

Retrieve this header’s next-layer hint, if possible.
Source§

impl<O: PartialEq, B: PartialEq> PartialEq for BoxedHeader<O, B>

Source§

fn eq(&self, other: &BoxedHeader<O, B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<O: NextLayer + Clone, B: NextLayer<Denom = O::Denom, Hint = O::Hint> + ToOwnedPacket<Target = O>> ToOwnedPacket for BoxedHeader<O, B>

Source§

type Target = O

The output type of this conversion.
Source§

fn to_owned(&self, hint: Option<Self::Hint>) -> ParseResult<Self::Target>

Converts a borrowed view of a header into an owned version, possibly reparsing to do so with the aid of hint.
Source§

impl<O: EmitDoesNotRelyOnBufContents, B: EmitDoesNotRelyOnBufContents> EmitDoesNotRelyOnBufContents for BoxedHeader<O, B>

Source§

impl<O: Eq, B: Eq> Eq for BoxedHeader<O, B>

Source§

impl<O, B> StructuralPartialEq for BoxedHeader<O, B>

Auto Trait Implementations§

§

impl<O, B> Freeze for BoxedHeader<O, B>
where B: Freeze,

§

impl<O, B> RefUnwindSafe for BoxedHeader<O, B>

§

impl<O, B> Send for BoxedHeader<O, B>
where B: Send, O: Send,

§

impl<O, B> Sync for BoxedHeader<O, B>
where B: Sync, O: Sync,

§

impl<O, B> Unpin for BoxedHeader<O, B>
where B: Unpin,

§

impl<O, B> UnwindSafe for BoxedHeader<O, B>
where B: UnwindSafe, O: 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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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.