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
impl Encode<Binary> for SocketAddrV4
Source§impl Encode<Binary> for SocketAddrV6
impl Encode<Binary> for SocketAddrV6
Source§impl Encode<Text> for SocketAddrV4
impl Encode<Text> for SocketAddrV4
Source§impl Encode<Text> for SocketAddrV6
impl Encode<Text> for SocketAddrV6
Source§impl<M> Encode<M> for SocketAddr
impl<M> Encode<M> for SocketAddr
Source§impl<M> Encode<M> for OsStrwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) only.
impl<M> Encode<M> for OsStrwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) only.Source§impl<M> Encode<M> for OsStringwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) only.
impl<M> Encode<M> for OsStringwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) only.Source§impl<M> Encode<M> for Pathwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) only.
impl<M> Encode<M> for Pathwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) only.Source§impl<M> Encode<M> for PathBufwhere
PlatformTag: Encode<M>,
Available on crate feature std and (Unix or Windows) only.
impl<M> Encode<M> for PathBufwhere
PlatformTag: Encode<M>,
Available on crate feature
std and (Unix or Windows) 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> Encode<M> for AtomicBool
Available on target_has_atomic=8 only.
impl<M> Encode<M> for AtomicBool
Available on
target_has_atomic=8 only.Source§impl<M> Encode<M> for AtomicIsize
Available on target_has_atomic=ptr only.
impl<M> Encode<M> for AtomicIsize
Available on
target_has_atomic=ptr only.Source§impl<M> Encode<M> for AtomicUsize
Available on target_has_atomic=ptr only.
impl<M> Encode<M> for AtomicUsize
Available on
target_has_atomic=ptr only.