pub trait Encode<M> {
type Encode: ?Sized + Encode<M>;
const IS_BITWISE_ENCODE: bool = false;
// Required methods
fn encode<E>(&self, encoder: E) -> Result<(), E::Error>
where E: Encoder<Mode = M>;
fn as_encode(&self) -> &Self::Encode;
// Provided method
fn size_hint(&self) -> Option<usize> { ... }
}Expand description
Trait governing how types are encoded.
This is typically implemented automatically using the Encode derive.
§Examples
use musli::Encode;
#[derive(Encode)]
struct MyType {
data: [u32; 8],
}Implementing manually:
use musli::{Encode, Encoder};
struct MyType {
data: [u32; 8],
}
impl<M> Encode<M> for MyType {
type Encode = Self;
#[inline]
fn encode<E>(&self, encoder: E) -> Result<(), E::Error>
where
E: Encoder<Mode = M>,
{
encoder.encode(&self.data)
}
#[inline]
fn as_encode(&self) -> &Self::Encode {
self
}
}Provided Associated Constants§
Sourceconst 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.
Note that setting this to true has safety implications, since it
implies that assuming the type is correctly aligned it can be validly
bitwise copied when encoded. Setting it to false is always safe.
This being set to true also implies that the type is Copy, and must
not have a Drop implementation.
Required Associated Types§
Required Methods§
Provided Methods§
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 Encode<Binary> for SocketAddrV4
Available on crate feature std only.
impl Encode<Binary> for SocketAddrV4
Available on crate feature
std only.Source§impl Encode<Binary> for SocketAddrV6
Available on crate feature std only.
impl Encode<Binary> for SocketAddrV6
Available on crate feature
std only.Source§impl Encode<Text> for SocketAddrV4
Available on crate feature std only.
impl Encode<Text> for SocketAddrV4
Available on crate feature
std only.Source§impl Encode<Text> for SocketAddrV6
Available on crate feature std only.
impl Encode<Text> for SocketAddrV6
Available on crate feature
std only.Source§impl<'de, M, K, V, S> Encode<M> for HashMap<K, V, S>
Available on crate features alloc and std only.
impl<'de, M, K, V, S> Encode<M> for HashMap<K, V, S>
Available on crate features
alloc and std only.Source§impl<M> Encode<M> for SocketAddr
Available on crate feature std only.
impl<M> Encode<M> for SocketAddr
Available on crate feature
std only.Source§impl<M> Encode<M> for OsStrwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) and crate feature alloc only.
impl<M> Encode<M> for OsStrwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) and crate feature alloc only.Source§impl<M> Encode<M> for OsStringwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) and crate feature alloc only.
impl<M> Encode<M> for OsStringwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) and crate feature alloc only.Source§impl<M> Encode<M> for Pathwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) and crate feature alloc only.
impl<M> Encode<M> for Pathwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) and crate feature alloc only.Source§impl<M> Encode<M> for PathBufwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) and crate feature alloc only.
impl<M> Encode<M> for PathBufwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) and crate feature alloc only.Source§impl<M> Encode<M> for NonZeroI16
impl<M> Encode<M> for NonZeroI16
Source§impl<M> Encode<M> for NonZeroI32
impl<M> Encode<M> for NonZeroI32
Source§impl<M> Encode<M> for NonZeroI64
impl<M> Encode<M> for NonZeroI64
Source§impl<M> Encode<M> for NonZeroI128
impl<M> Encode<M> for NonZeroI128
Source§impl<M> Encode<M> for NonZeroIsize
impl<M> Encode<M> for NonZeroIsize
Source§impl<M> Encode<M> for NonZeroU16
impl<M> Encode<M> for NonZeroU16
Source§impl<M> Encode<M> for NonZeroU32
impl<M> Encode<M> for NonZeroU32
Source§impl<M> Encode<M> for NonZeroU64
impl<M> Encode<M> for NonZeroU64
Source§impl<M> Encode<M> for NonZeroU128
impl<M> Encode<M> for NonZeroU128
Source§impl<M> Encode<M> for NonZeroUsize
impl<M> Encode<M> for NonZeroUsize
Source§impl<M, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<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> Encode<M> for (T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
impl<M, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
Source§impl<M, T7, T8, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T7, T8, T9, T10, T11, T12, T13, T14, T15)
impl<M, T7, T8, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T7, T8, T9, T10, T11, T12, T13, T14, T15)
Source§impl<M, T8, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T8, T9, T10, T11, T12, T13, T14, T15)
impl<M, T8, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T8, T9, T10, T11, T12, T13, T14, T15)
Source§impl<M, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T9, T10, T11, T12, T13, T14, T15)
impl<M, T9, T10, T11, T12, T13, T14, T15> Encode<M> for (T9, T10, T11, T12, T13, T14, T15)
Source§impl<M, T10, T11, T12, T13, T14, T15> Encode<M> for (T10, T11, T12, T13, T14, T15)
impl<M, T10, T11, T12, T13, T14, T15> Encode<M> for (T10, T11, T12, T13, T14, T15)
Source§impl<M, T11, T12, T13, T14, T15> Encode<M> for (T11, T12, T13, T14, T15)
impl<M, T11, T12, T13, T14, T15> Encode<M> for (T11, T12, T13, T14, T15)
Source§impl<M, T12, T13, T14, T15> Encode<M> for (T12, T13, T14, T15)
impl<M, T12, T13, T14, T15> Encode<M> for (T12, T13, T14, T15)
Source§impl<M, T13, T14, T15> Encode<M> for (T13, T14, T15)
impl<M, T13, T14, T15> Encode<M> for (T13, T14, T15)
Source§impl<M, T14, T15> Encode<M> for (T14, T15)
impl<M, T14, T15> Encode<M> for (T14, T15)
Source§impl<M, T> Encode<M> for BinaryHeap<T>where
T: Encode<M>,
Available on crate feature alloc only.
impl<M, T> Encode<M> for BinaryHeap<T>where
T: Encode<M>,
Available on crate feature
alloc only.Source§impl<M, T> Encode<M> for BTreeSet<T>where
T: Encode<M>,
Available on crate feature alloc only.
impl<M, T> Encode<M> for BTreeSet<T>where
T: Encode<M>,
Available on crate feature
alloc only.Source§impl<M, T> Encode<M> for VecDeque<T>where
T: Encode<M>,
Available on crate feature alloc only.
impl<M, T> Encode<M> for VecDeque<T>where
T: Encode<M>,
Available on crate feature
alloc only.