pub trait Encode {
// Required method
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>;
}Expand description
Any source that can be encoded. This trait should be implemented for all types that you want to be able to use with any of the encode_with methods.
This trait will be automatically implemented if you enable the derive feature and add #[derive(bincode::Encode)] to your trait.
§Implementing this trait manually
If you want to implement this trait for your type, the easiest way is to add a #[derive(bincode::Encode)], build and check your target/generated/bincode/ folder. This should generate a <Struct name>_Encode.rs file.
For this struct:
struct Entity {
pub x: f32,
pub y: f32,
}It will look something like:
impl bincode::Encode for Entity {
fn encode<E: bincode::enc::Encoder>(
&self,
encoder: &mut E,
) -> core::result::Result<(), bincode::error::EncodeError> {
bincode::Encode::encode(&self.x, encoder)?;
bincode::Encode::encode(&self.y, encoder)?;
Ok(())
}
}From here you can add/remove fields, or add custom logic.
Required 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 for SocketAddr
Available on crate feature std only.
impl Encode for SocketAddr
Available on crate feature
std only.Source§impl Encode for SocketAddrV4
Available on crate feature std only.
impl Encode for SocketAddrV4
Available on crate feature
std only.Source§impl Encode for SocketAddrV6
Available on crate feature std only.
impl Encode for SocketAddrV6
Available on crate feature
std only.Source§impl Encode for AtomicBool
Available on target_has_atomic=8 only.
impl Encode for AtomicBool
Available on
target_has_atomic=8 only.Source§impl Encode for AtomicIsize
Available on target_has_atomic=ptr only.
impl Encode for AtomicIsize
Available on
target_has_atomic=ptr only.Source§impl Encode for AtomicUsize
Available on target_has_atomic=ptr only.
impl Encode for AtomicUsize
Available on
target_has_atomic=ptr only.Source§impl Encode for SystemTime
Available on crate feature std only.
impl Encode for SystemTime
Available on crate feature
std only.Source§impl Encode for NonZeroI16
impl Encode for NonZeroI16
Source§impl Encode for NonZeroI32
impl Encode for NonZeroI32
Source§impl Encode for NonZeroI64
impl Encode for NonZeroI64
Source§impl Encode for NonZeroI128
impl Encode for NonZeroI128
Source§impl Encode for NonZeroIsize
impl Encode for NonZeroIsize
Source§impl Encode for NonZeroU16
impl Encode for NonZeroU16
Source§impl Encode for NonZeroU32
impl Encode for NonZeroU32
Source§impl Encode for NonZeroU64
impl Encode for NonZeroU64
Source§impl Encode for NonZeroU128
impl Encode for NonZeroU128
Source§impl Encode for NonZeroUsize
impl Encode for NonZeroUsize
Source§impl<A, B, C, D> Encode for (A, B, C, D)
impl<A, B, C, D> Encode for (A, B, C, D)
Source§impl<A, B, C, D, E> Encode for (A, B, C, D, E)
impl<A, B, C, D, E> Encode for (A, B, C, D, E)
Source§impl<A, B, C, D, E, F> Encode for (A, B, C, D, E, F)
impl<A, B, C, D, E, F> Encode for (A, B, C, D, E, F)
Source§impl<A, B, C, D, E, F, G> Encode for (A, B, C, D, E, F, G)
impl<A, B, C, D, E, F, G> Encode for (A, B, C, D, E, F, G)
Source§impl<A, B, C, D, E, F, G, H> Encode for (A, B, C, D, E, F, G, H)
impl<A, B, C, D, E, F, G, H> Encode for (A, B, C, D, E, F, G, H)
Source§impl<A, B, C, D, E, F, G, H, I> Encode for (A, B, C, D, E, F, G, H, I)
impl<A, B, C, D, E, F, G, H, I> Encode for (A, B, C, D, E, F, G, H, I)
Source§impl<A, B, C, D, E, F, G, H, I, J> Encode for (A, B, C, D, E, F, G, H, I, J)
impl<A, B, C, D, E, F, G, H, I, J> Encode for (A, B, C, D, E, F, G, H, I, J)
Source§impl<A, B, C, D, E, F, G, H, I, J, K> Encode for (A, B, C, D, E, F, G, H, I, J, K)
impl<A, B, C, D, E, F, G, H, I, J, K> Encode for (A, B, C, D, E, F, G, H, I, J, K)
Source§impl<A, B, C, D, E, F, G, H, I, J, K, L> Encode for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<A, B, C, D, E, F, G, H, I, J, K, L> Encode for (A, B, C, D, E, F, G, H, I, J, K, L)
Source§impl<A, B, C, D, E, F, G, H, I, J, K, L, M> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M)
impl<A, B, C, D, E, F, G, H, I, J, K, L, M> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M)
Source§impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
Source§impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
Source§impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Encode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
Source§impl<T> Encode for BinaryHeap<T>
Available on crate feature alloc only.
impl<T> Encode for BinaryHeap<T>
Available on crate feature
alloc only.