Skip to main content

Prefixed

Struct Prefixed 

pub struct Prefixed<P, T> {
    prefix: P,
    value: T,
}
Expand description

A string or array with a length prefix of type P.

Decode Utf8Bytes or Bytes for strings and byte arrays, and Items for other arrays. Encode borrowed values, such as &str or &[T].

§Example

use ql_qmi::codec::{Encode, Prefixed, Reader, Utf8Bytes};

let mut out = Vec::new();
Prefixed::<u8, _>::new("228").unwrap().encode(&mut out);
assert_eq!(out, [3, b'2', b'2', b'8']);

let mcc: Prefixed<u8, Utf8Bytes> = Reader::new(out.into()).read().unwrap();
assert_eq!(mcc.get(), "228");

Fields§

§prefix: P§value: T

Implementations§

§

impl<P: LengthPrefix, T: Sequence> Prefixed<P, T>

pub fn new(value: T) -> Option<Self>

Returns None if value is too long for the prefix.

§

impl<P, T> Prefixed<P, T>

pub const fn get(&self) -> &T

Returns the value.

pub fn into_inner(self) -> T

Returns the value.

Trait Implementations§

§

impl<P: Clone, T: Clone> Clone for Prefixed<P, T>

§

fn clone(&self) -> Prefixed<P, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<P: Copy, T: Copy> Copy for Prefixed<P, T>

§

impl<P: Debug, T: Debug> Debug for Prefixed<P, T>

§

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

Formats the value using the given formatter. Read more
§

impl<P: LengthPrefix> Decode for Prefixed<P, Bytes>

§

fn decode(reader: &mut Reader) -> Result<Self, ValueError>

Reads a value. Read more
§

impl<P: LengthPrefix> Decode for Prefixed<P, Utf8Bytes>

§

fn decode(reader: &mut Reader) -> Result<Self, ValueError>

Reads a value. Read more
§

impl<P: LengthPrefix, T: Decode> Decode for Prefixed<P, Items<T>>

§

fn decode(reader: &mut Reader) -> Result<Self, ValueError>

Reads a value. Read more
§

impl<P: Encode, T: Encode> Encode for Prefixed<P, T>

§

fn encode<B: BufMut + ?Sized>(&self, out: &mut B)

Appends the encoded value to out.
§

impl<P: Eq, T: Eq> Eq for Prefixed<P, T>

§

impl<P: Hash, T: Hash> Hash for Prefixed<P, T>

§

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
§

impl<P: PartialEq, T: PartialEq> PartialEq for Prefixed<P, T>

§

fn eq(&self, other: &Prefixed<P, T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
§

impl<P: PartialEq, T: PartialEq> StructuralPartialEq for Prefixed<P, T>

Auto Trait Implementations§

§

impl<P, T> Freeze for Prefixed<P, T>
where P: Freeze, T: Freeze,

§

impl<P, T> RefUnwindSafe for Prefixed<P, T>

§

impl<P, T> Send for Prefixed<P, T>
where P: Send, T: Send,

§

impl<P, T> Sync for Prefixed<P, T>
where P: Sync, T: Sync,

§

impl<P, T> Unpin for Prefixed<P, T>
where P: Unpin, T: Unpin,

§

impl<P, T> UnsafeUnpin for Prefixed<P, T>
where P: UnsafeUnpin, T: UnsafeUnpin,

§

impl<P, T> UnwindSafe for Prefixed<P, T>
where P: UnwindSafe, T: 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more