Trait musli::en::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§
Object Safety§
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
source§impl<M, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T7, T8, T9, T10, T11, T12, T13, T14, T15)
impl<M, T7, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T7, T8, T9, T10, T11, T12, T13, T14, T15)
source§impl<M, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T8, T9, T10, T11, T12, T13, T14, T15)
impl<M, T8, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T8, T9, T10, T11, T12, T13, T14, T15)
source§impl<M, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T9, T10, T11, T12, T13, T14, T15)
impl<M, T9, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T9, T10, T11, T12, T13, T14, T15)
source§impl<M, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T10, T11, T12, T13, T14, T15)
impl<M, T10, T11, T12, T13, T14, T15> EncodePacked<M> for (T10, T11, T12, T13, T14, T15)
source§impl<M, T11, T12, T13, T14, T15> EncodePacked<M> for (T11, T12, T13, T14, T15)
impl<M, T11, T12, T13, T14, T15> EncodePacked<M> for (T11, T12, T13, T14, T15)
source§impl<M, T12, T13, T14, T15> EncodePacked<M> for (T12, T13, T14, T15)
impl<M, T12, T13, T14, T15> EncodePacked<M> for (T12, T13, T14, T15)
source§impl<M, T13, T14, T15> EncodePacked<M> for (T13, T14, T15)
impl<M, T13, T14, T15> EncodePacked<M> for (T13, T14, T15)
source§impl<M, T14, T15> EncodePacked<M> for (T14, T15)
impl<M, T14, T15> EncodePacked<M> for (T14, T15)
source§impl<M, T15> EncodePacked<M> for (T15,)where
T15: Encode<M>,
impl<M, T15> EncodePacked<M> for (T15,)where
T15: Encode<M>,
source§impl<M, T> EncodePacked<M> for BinaryHeap<T>where
T: Encode<M>,
Available on crate feature alloc
only.
impl<M, T> EncodePacked<M> for BinaryHeap<T>where
T: Encode<M>,
Available on crate feature
alloc
only.source§impl<M, T> EncodePacked<M> for BTreeSet<T>where
T: Encode<M>,
Available on crate feature alloc
only.
impl<M, T> EncodePacked<M> for BTreeSet<T>where
T: Encode<M>,
Available on crate feature
alloc
only.source§impl<M, T> EncodePacked<M> for VecDeque<T>where
T: Encode<M>,
Available on crate feature alloc
only.
impl<M, T> EncodePacked<M> for VecDeque<T>where
T: Encode<M>,
Available on crate feature
alloc
only.source§impl<M, T> EncodePacked<M> for Vec<T>where
T: Encode<M>,
Available on crate feature alloc
only.
impl<M, T> EncodePacked<M> for Vec<T>where
T: Encode<M>,
Available on crate feature
alloc
only.source§impl<M, T, S> EncodePacked<M> for HashSet<T, S>
Available on crate features alloc
and std
only.
impl<M, T, S> EncodePacked<M> for HashSet<T, S>
Available on crate features
alloc
and std
only.