musli_core::de

Trait DecodePacked

Source
pub trait DecodePacked<'de, M>: Sized {
    // Required method
    fn decode_packed<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
       where D: Decoder<'de, Mode = M>;
}
Expand description

Trait governing how a type is decoded as a packed value.

Packed encodings are ones where data follow one after another, with no “metadata” indicating when one value starts and another stops.

This is typically used automatically through the #[musli(packed)] attribute through the Decode derive.

§Examples

use musli::Decode;

#[derive(Decode)]
struct Packed {
    #[musli(packed)]
    data: (u32, u32),
}

Implementing manually:

use musli::{Decode, Decoder};
use musli::de::SequenceDecoder;

struct Packed {
    data: (u32, u32),
}

impl<'de, M> Decode<'de, M> for Packed {
    fn decode<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
    where
        D: Decoder<'de>,
    {
        decoder.decode_pack(|pack| {
            Ok(Self {
                data: (pack.next()?, pack.next()?),
            })
        })
    }
}

Required Methods§

Source

fn decode_packed<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Decode the given input as bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'de, M, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T0: Decode<'de, M>, T1: Decode<'de, M>, T2: Decode<'de, M>, T3: Decode<'de, M>, T4: Decode<'de, M>, T5: Decode<'de, M>, T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T1: Decode<'de, M>, T2: Decode<'de, M>, T3: Decode<'de, M>, T4: Decode<'de, M>, T5: Decode<'de, M>, T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T2: Decode<'de, M>, T3: Decode<'de, M>, T4: Decode<'de, M>, T5: Decode<'de, M>, T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T3: Decode<'de, M>, T4: Decode<'de, M>, T5: Decode<'de, M>, T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T4: Decode<'de, M>, T5: Decode<'de, M>, T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T5: Decode<'de, M>, T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T6: Decode<'de, M>, T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T7, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T7: Decode<'de, M>, T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T8, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T8, T9, T10, T11, T12, T13, T14, T15)
where T8: Decode<'de, M>, T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T9, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T9, T10, T11, T12, T13, T14, T15)
where T9: Decode<'de, M>, T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T10, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T10, T11, T12, T13, T14, T15)
where T10: Decode<'de, M>, T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T11, T12, T13, T14, T15> DecodePacked<'de, M> for (T11, T12, T13, T14, T15)
where T11: Decode<'de, M>, T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T12, T13, T14, T15> DecodePacked<'de, M> for (T12, T13, T14, T15)
where T12: Decode<'de, M>, T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T13, T14, T15> DecodePacked<'de, M> for (T13, T14, T15)
where T13: Decode<'de, M>, T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T14, T15> DecodePacked<'de, M> for (T14, T15)
where T14: Decode<'de, M>, T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T15> DecodePacked<'de, M> for (T15,)
where T15: Decode<'de, M>,

Source§

fn decode_packed<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, T, const N: usize> DecodePacked<'de, M> for [T; N]
where T: Decode<'de, M>,

Source§

fn decode_packed<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Implementors§