Skip to main content

FromBinary

Trait FromBinary 

Source
pub unsafe trait FromBinary<'a>: Sized {
    const POD: bool = false;

    // Required method
    fn decode_binary(decoder: &mut Decoder<'a>) -> Self;
}
Expand description

A trait for parsing a value from a compact binary representation.

§Safety

This trait is safe to implement if you only override decode_binary and leave other methods as default. However, setting POD = true requires additional safety considerations.

§Usage

Given a decoder, decode_binary will attempt to decode Self from the prefix of the decoder. This method always returns a value, even in case of an error. When an error occurs, a default value is returned. This approach is primarily an optimization but can also be used to extract partial values when parsing as a whole has failed.

§Error Handling

Errors are stored in the decoder rather than being returned directly by decode_binary.

§Plain Old Data (POD)

Setting POD = true indicates that this type can be directly memory-copied from the input and maintains the same representation as if it was encoded field-by-field in the binary decoder.

§Requirements for POD = true:

  • Every bit must be valid for the type and layout.
  • There must be no padding between fields.
  • Fields must be laid out in the same order as they are encoded and decoded by decode_binary.

Provided Associated Constants§

Source

const POD: bool = false

Indicates whether this type is Plain Old Data (POD).

Required Methods§

Source

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Decodes Self from the given decoder.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, K: FromBinary<'a> + Eq + Hash, S: BuildHasher + Default> FromBinary<'a> for HashSet<K, S>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, K: FromBinary<'a> + Eq + Hash, V: FromBinary<'a>, S: BuildHasher + Default> FromBinary<'a> for HashMap<K, V, S>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, K: FromBinary<'a> + Ord, V: FromBinary<'a>> FromBinary<'a> for BTreeMap<K, V>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, K: FromBinary<'a> + Ord> FromBinary<'a> for BTreeSet<K>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T0: FromBinary<'a>, T1: FromBinary<'a>, T2: FromBinary<'a>> FromBinary<'a> for (T0, T1, T2)

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T0: FromBinary<'a>, T1: FromBinary<'a>> FromBinary<'a> for (T0, T1)

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T0: FromBinary<'a>> FromBinary<'a> for (T0,)

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T: FromBinary<'a>, const N: usize> FromBinary<'a> for [T; N]

Source§

const POD: bool = T::POD

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T: FromBinary<'a>> FromBinary<'a> for &'a [T]

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T: FromBinary<'a>> FromBinary<'a> for Box<T>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T: FromBinary<'a>> FromBinary<'a> for Box<[T]>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T: FromBinary<'a>> FromBinary<'a> for Option<T>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T: FromBinary<'a>> FromBinary<'a> for Vec<T>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a, T> FromBinary<'a> for Cow<'a, [T]>
where T: ToOwned + Clone + FromBinary<'a>,

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for &'a str

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for Box<str>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for Cow<'a, str>

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for Duration

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for String

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for bool

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for char

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for f32

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for f64

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for i8

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for i16

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for i32

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for i64

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for i128

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for u8

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for u16

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for u32

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for u64

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Source§

impl<'a> FromBinary<'a> for u128

Source§

const POD: bool = true

Source§

fn decode_binary(decoder: &mut Decoder<'a>) -> Self

Implementors§