Struct Record

Source
pub struct Record<Len: LenType, T> {
    pub data: T,
    /* private fields */
}
Expand description

Record can be used to encode collections where the size of the length is known.

For example, Record<u8, String> here the maximum allowed payload length is 255 (u8::MAX)

§Example

use bin_layout::*;

let record: Record<u8, String> = "very long string!".repeat(15).into();
let bytes = record.encode();
assert_eq!(record.len(), 255);
assert_eq!(bytes.len(), 256);

Fields§

§data: T

Implementations§

Source§

impl<Len: LenType, T> Record<Len, T>

Source

pub const fn new(data: T) -> Self

Trait Implementations§

Source§

impl<Len: Clone + LenType, T: Clone> Clone for Record<Len, T>

Source§

fn clone(&self) -> Record<Len, T>

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<Len: LenType, T: Debug> Debug for Record<Len, T>

Source§

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

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

impl<'de: 'a, 'a, Len: LenType> Decoder<'de> for Record<Len, &'a [u8]>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de: 'a, 'a, Len: LenType> Decoder<'de> for Record<Len, &'a str>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, K: Decoder<'de> + Ord, V: Decoder<'de>> Decoder<'de> for Record<Len, BTreeMap<K, V>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, T: Decoder<'de> + Ord> Decoder<'de> for Record<Len, BTreeSet<T>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, T: Decoder<'de> + Ord> Decoder<'de> for Record<Len, BinaryHeap<T>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, K: Decoder<'de> + Eq + Hash, V: Decoder<'de>, S: BuildHasher + Default> Decoder<'de> for Record<Len, HashMap<K, V, S>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, T: Decoder<'de> + Eq + Hash, S: BuildHasher + Default> Decoder<'de> for Record<Len, HashSet<T, S>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, T: Decoder<'de>> Decoder<'de> for Record<Len, LinkedList<T>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType> Decoder<'de> for Record<Len, String>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, T: Decoder<'de>> Decoder<'de> for Record<Len, Vec<T>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<'de, Len: LenType, T: Decoder<'de>> Decoder<'de> for Record<Len, VecDeque<T>>

Source§

fn decoder(c: &mut &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Deserialize the data from binary format.
Source§

fn decode(data: &'de [u8]) -> Result<Self, Box<dyn Error + Send + Sync>>

Example Read more
Source§

impl<Len: Default + LenType, T: Default> Default for Record<Len, T>

Source§

fn default() -> Record<Len, T>

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

impl<Len: LenType, T> Deref for Record<Len, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Len: LenType, T> DerefMut for Record<Len, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Len: LenType, T: Encoder> Encoder for Record<Len, &[T]>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType> Encoder for Record<Len, &str>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, K: Encoder, V: Encoder> Encoder for Record<Len, BTreeMap<K, V>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T: Encoder> Encoder for Record<Len, BTreeSet<T>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T: Encoder> Encoder for Record<Len, BinaryHeap<T>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, K: Encoder, V: Encoder, S> Encoder for Record<Len, HashMap<K, V, S>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T: Encoder, S> Encoder for Record<Len, HashSet<T, S>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T: Encoder> Encoder for Record<Len, LinkedList<T>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType> Encoder for Record<Len, String>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T: Encoder> Encoder for Record<Len, Vec<T>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T: Encoder> Encoder for Record<Len, VecDeque<T>>

Source§

fn encoder(&self, c: &mut impl Write) -> Result<()>

Serialize the data into binary format.
Source§

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

Example Read more
Source§

impl<Len: LenType, T> From<T> for Record<Len, T>

Source§

fn from(data: T) -> Self

Converts to this type from the input type.
Source§

impl<Len: LenType, T, V: FromIterator<T>> FromIterator<T> for Record<Len, V>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<Len: Ord + LenType, T: Ord> Ord for Record<Len, T>

Source§

fn cmp(&self, other: &Record<Len, T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Len: PartialEq + LenType, T: PartialEq> PartialEq for Record<Len, T>

Source§

fn eq(&self, other: &Record<Len, T>) -> 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<Len: PartialOrd + LenType, T: PartialOrd> PartialOrd for Record<Len, T>

Source§

fn partial_cmp(&self, other: &Record<Len, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Len: Eq + LenType, T: Eq> Eq for Record<Len, T>

Source§

impl<Len: LenType, T> StructuralPartialEq for Record<Len, T>

Auto Trait Implementations§

§

impl<Len, T> Freeze for Record<Len, T>
where T: Freeze,

§

impl<Len, T> RefUnwindSafe for Record<Len, T>

§

impl<Len, T> Send for Record<Len, T>
where T: Send, Len: Send,

§

impl<Len, T> Sync for Record<Len, T>
where T: Sync, Len: Sync,

§

impl<Len, T> Unpin for Record<Len, T>
where T: Unpin, Len: Unpin,

§

impl<Len, T> UnwindSafe for Record<Len, T>
where T: UnwindSafe, Len: 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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.