Struct tlv_rs::TLV

source ·
pub struct TLV<Type, Length, EncodedType, Payload> {
    pub tlv_type: EncodedType,
    pub payload: Payload,
    pub _phantom: PhantomData<(Type, Length)>,
}
Expand description

A TLV.

This has to be constructed with ..Default::default() as internally there exists a PhantomData. The first type parameter is the raw type of the tlv type. The second is the strongly typed tlv type, which has to implement conversions from and into the raw tlv type. The third parameter is the type of the length of the TLV. The last parameter is a constant boolean, which describes if the fields should be encoded using big endian.

Fields§

§tlv_type: EncodedType§payload: Payload§_phantom: PhantomData<(Type, Length)>

Implementations§

source§

impl<'a, Type: TryFromCtx<'a, Endian, Error = Error> + TryIntoCtx<Endian, Error = Error> + From<EncodedType>, Length: 'a + TryFromCtx<'a, Endian, Error = Error> + TryIntoCtx<Endian, Error = Error> + TryInto<usize> + TryFrom<usize>, EncodedType: 'a + From<Type>, Payload: TryFromCtx<'a, Error = Error> + TryIntoCtx<Error = Error> + MeasureWith<()>> TLV<Type, Length, EncodedType, Payload>

source

pub fn from_bytes(bytes: &'a [u8], big_endian: bool) -> Result<Self, Error>

Wrapper around scroll Pread.

source

pub fn into_bytes( self, buf: &mut [u8], big_endian: bool ) -> Result<usize, Error>

Serialize into the buffer.

source

pub fn into_bytes_capped<const N: usize>( self, big_endian: bool ) -> Result<Vec<u8, N>, Error>

Serialize into a heapless::Vec.

Trait Implementations§

source§

impl<Type: Clone, Length: Clone, EncodedType: Clone, Payload: Clone> Clone for TLV<Type, Length, EncodedType, Payload>

source§

fn clone(&self) -> TLV<Type, Length, EncodedType, Payload>

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<Type: Debug, Length: Debug, EncodedType: Debug, Payload: Debug> Debug for TLV<Type, Length, EncodedType, Payload>

source§

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

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

impl<Type: Default, Length: Default, EncodedType: Default, Payload: Default> Default for TLV<Type, Length, EncodedType, Payload>

source§

fn default() -> TLV<Type, Length, EncodedType, Payload>

Returns the “default value” for a type. Read more
source§

impl<Type: SizeWith, Length: SizeWith, EncodedType: From<Type>, Payload: MeasureWith<()>> MeasureWith<()> for TLV<Type, Length, EncodedType, Payload>

source§

fn measure_with(&self, ctx: &()) -> usize

How large is Self, given the ctx?
source§

impl<Type: PartialEq, Length: PartialEq, EncodedType: PartialEq, Payload: PartialEq> PartialEq for TLV<Type, Length, EncodedType, Payload>

source§

fn eq(&self, other: &TLV<Type, Length, EncodedType, Payload>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, Type: TryFromCtx<'a, Endian, Error = Error>, Length: TryFromCtx<'a, Endian, Error = Error> + TryInto<usize>, EncodedType: 'a + From<Type>, Payload: TryFromCtx<'a, Error = Error>> TryFromCtx<'a, Endian> for TLV<Type, Length, EncodedType, Payload>

§

type Error = Error

source§

fn try_from_ctx( from: &'a [u8], ctx: Endian ) -> Result<(Self, usize), Self::Error>

source§

impl<Type: TryIntoCtx<Endian, Error = Error>, Length: TryIntoCtx<Endian, Error = Error> + TryFrom<usize>, EncodedType: Into<Type>, Payload: TryIntoCtx<Error = Error> + MeasureWith<()>> TryIntoCtx<Endian> for TLV<Type, Length, EncodedType, Payload>

§

type Error = Error

source§

fn try_into_ctx(self, buf: &mut [u8], ctx: Endian) -> Result<usize, Self::Error>

source§

impl<Type: Eq, Length: Eq, EncodedType: Eq, Payload: Eq> Eq for TLV<Type, Length, EncodedType, Payload>

source§

impl<Type, Length, EncodedType, Payload> StructuralEq for TLV<Type, Length, EncodedType, Payload>

source§

impl<Type, Length, EncodedType, Payload> StructuralPartialEq for TLV<Type, Length, EncodedType, Payload>

Auto Trait Implementations§

§

impl<Type, Length, EncodedType, Payload> RefUnwindSafe for TLV<Type, Length, EncodedType, Payload>
where EncodedType: RefUnwindSafe, Length: RefUnwindSafe, Payload: RefUnwindSafe, Type: RefUnwindSafe,

§

impl<Type, Length, EncodedType, Payload> Send for TLV<Type, Length, EncodedType, Payload>
where EncodedType: Send, Length: Send, Payload: Send, Type: Send,

§

impl<Type, Length, EncodedType, Payload> Sync for TLV<Type, Length, EncodedType, Payload>
where EncodedType: Sync, Length: Sync, Payload: Sync, Type: Sync,

§

impl<Type, Length, EncodedType, Payload> Unpin for TLV<Type, Length, EncodedType, Payload>
where EncodedType: Unpin, Length: Unpin, Payload: Unpin, Type: Unpin,

§

impl<Type, Length, EncodedType, Payload> UnwindSafe for TLV<Type, Length, EncodedType, Payload>
where EncodedType: UnwindSafe, Length: UnwindSafe, Payload: UnwindSafe, Type: 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> 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, 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.