#[repr(transparent)]pub struct Bytes<T>(pub T);Expand description
Treat T as if its bytes.
This corresponds to the “Bytes” type in the data model of Müsli and is the
equivalent of using #[musli(bytes)] 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 EncodeBytes
and DecodeBytes.
§Examples
use musli::{Allocator, Decode, Decoder};
use musli::compat::Bytes;
struct Struct {
field: Vec<u8>,
}
impl<'de, M, A> Decode<'de, M, A> for Struct
where
A: Allocator,
Bytes<Vec<u8>>: Decode<'de, M, A>
{
#[inline]
fn decode<D>(decoder: D) -> Result<Self, D::Error>
where
D: Decoder<'de, Mode = M, Allocator = A>,
{
let Bytes(field) = decoder.decode()?;
Ok(Struct {
field,
})
}
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<'de, T, A> Decode<'de, Binary, A> for Bytes<T>
impl<'de, T, A> Decode<'de, Binary, A> for Bytes<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 Bytes<T>
impl<'de, T, A> Decode<'de, Text, A> for Bytes<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 Bytes<T>where
T: EncodeBytes<Binary>,
impl<T> Encode<Binary> for Bytes<T>where
T: EncodeBytes<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 Bytes<T>where
T: EncodeBytes<Text>,
impl<T> Encode<Text> for Bytes<T>where
T: EncodeBytes<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
Source§impl<T: Ord> Ord for Bytes<T>
impl<T: Ord> Ord for Bytes<T>
Source§impl<T: PartialOrd> PartialOrd for Bytes<T>
impl<T: PartialOrd> PartialOrd for Bytes<T>
impl<T: Copy> Copy for Bytes<T>
impl<T: Eq> Eq for Bytes<T>
impl<T> StructuralPartialEq for Bytes<T>
Auto Trait Implementations§
impl<T> Freeze for Bytes<T>where
T: Freeze,
impl<T> RefUnwindSafe for Bytes<T>where
T: RefUnwindSafe,
impl<T> Send for Bytes<T>where
T: Send,
impl<T> Sync for Bytes<T>where
T: Sync,
impl<T> Unpin for Bytes<T>where
T: Unpin,
impl<T> UnwindSafe for Bytes<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