musli_core::en

Trait EncodePacked

Source
pub trait EncodePacked<M> {
    // Required method
    fn encode_packed<E>(
        &self,
        cx: &E::Cx,
        encoder: E,
    ) -> Result<E::Ok, E::Error>
       where E: Encoder<Mode = M>;
}
Expand description

Trait governing how a type is encoded 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::Encode;

#[derive(Encode)]
struct PackedType {
    #[musli(packed)]
    data: (u32, u32),
}

Implementing manually:

use musli::{Encode, Encoder};
use musli::en::SequenceEncoder;

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

impl<M> Encode<M> for PackedType {
    fn encode<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
    where
        E: Encoder,
    {
        let mut pack = encoder.encode_pack()?;
        pack.push(&self.data.0);
        pack.push(&self.data.1);
        pack.finish_sequence()
    }
}

Required Methods§

Source

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Encode the given output 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<M, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T0: Encode<M>, T1: Encode<M>, T2: Encode<M>, T3: Encode<M>, T4: Encode<M>, T5: Encode<M>, T6: Encode<M>, T7: Encode<M>, T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

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

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

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

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T3: Encode<M>, T4: Encode<M>, T5: Encode<M>, T6: Encode<M>, T7: Encode<M>, T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T4: Encode<M>, T5: Encode<M>, T6: Encode<M>, T7: Encode<M>, T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T5: Encode<M>, T6: Encode<M>, T7: Encode<M>, T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T6: Encode<M>, T7: Encode<M>, T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T7, T8, T9, T10, T11, T12, T13, T14, T15)
where T7: Encode<M>, T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T8, T9, T10, T11, T12, T13, T14, T15)
where T8: Encode<M>, T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T9, T10, T11, T12, T13, T14, T15)
where T9: Encode<M>, T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T10, T11, T12, T13, T14, T15)
where T10: Encode<M>, T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T11, T12, T13, T14, T15> EncodePacked<M> for (T11, T12, T13, T14, T15)
where T11: Encode<M>, T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T12, T13, T14, T15> EncodePacked<M> for (T12, T13, T14, T15)
where T12: Encode<M>, T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T13, T14, T15> EncodePacked<M> for (T13, T14, T15)
where T13: Encode<M>, T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T14, T15> EncodePacked<M> for (T14, T15)
where T14: Encode<M>, T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T15> EncodePacked<M> for (T15,)
where T15: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T> EncodePacked<M> for BinaryHeap<T>
where T: Encode<M>,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T> EncodePacked<M> for BTreeSet<T>
where T: Encode<M>,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T> EncodePacked<M> for VecDeque<T>
where T: Encode<M>,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T> EncodePacked<M> for Vec<T>
where T: Encode<M>,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T, S> EncodePacked<M> for HashSet<T, S>
where T: Encode<M>, S: BuildHasher + Default,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<M, T, const N: usize> EncodePacked<M> for [T; N]
where T: Encode<M>,

Source§

fn encode_packed<E>(&self, _: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<T, M> EncodePacked<M> for &T
where T: ?Sized + EncodePacked<M>,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Source§

impl<T, M> EncodePacked<M> for &mut T
where T: ?Sized + EncodePacked<M>,

Source§

fn encode_packed<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>,

Implementors§