#[repr(transparent)]pub struct Packed<T>(pub T);Expand description
Treat T as if its packed.
This corresponds to the “Bytes” type in the [data model of Müsli]. It
encodes any Encode / Decode type “on after another” and is the
equivalent of using #[musli(packed)] on a field.
This is only implemented for type where the default behavior is not to pack
the value already, this applies to types which implements EncodePacked
and DecodePacked.
§Examples
use musli::{Allocator, Decode, Decoder};
use musli::compat::Packed;
struct Struct {
field: u8,
field2: u32,
}
impl<'de, M, A> Decode<'de, M, A> for Struct
where
A: Allocator,
Packed<(u8, u32)>: Decode<'de, M, A>
{
#[inline]
fn decode<D>(decoder: D) -> Result<Self, D::Error>
where
D: Decoder<'de, Mode = M, Allocator = A>,
{
let Packed((field, field2)) = decoder.decode()?;
Ok(Struct {
field,
field2,
})
}
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<'de, T, A> Decode<'de, Binary, A> for Packed<T>
impl<'de, T, A> Decode<'de, Binary, A> for Packed<T>
Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Whether the type is packed. Packed types can be bitwise copied if the
representation of the serialization format is identical to the memory
layout of the type. Read more
Source§impl<'de, T, A> Decode<'de, Text, A> for Packed<T>
impl<'de, T, A> Decode<'de, Text, A> for Packed<T>
Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Whether the type is packed. Packed types can be bitwise copied if the
representation of the serialization format is identical to the memory
layout of the type. Read more
Source§impl<T> Encode<Binary> for Packed<T>where
T: EncodePacked<Binary>,
impl<T> Encode<Binary> for Packed<T>where
T: EncodePacked<Binary>,
Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Whether the type is packed. Packed types can be bitwise copied if the
representation of the serialization format is identical to the memory
layout of the type. Read more
Source§impl<T> Encode<Text> for Packed<T>where
T: EncodePacked<Text>,
impl<T> Encode<Text> for Packed<T>where
T: EncodePacked<Text>,
Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Whether the type is packed. Packed types can be bitwise copied if the
representation of the serialization format is identical to the memory
layout of the type. Read more
Auto Trait Implementations§
impl<T> Freeze for Packed<T>where
T: Freeze,
impl<T> RefUnwindSafe for Packed<T>where
T: RefUnwindSafe,
impl<T> Send for Packed<T>where
T: Send,
impl<T> Sync for Packed<T>where
T: Sync,
impl<T> Unpin for Packed<T>where
T: Unpin,
impl<T> UnwindSafe for Packed<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more