Trait bincode::enc::Encode

source ·
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§

source

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

Encode a given type.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Encode for &Path

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for IpAddr

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for SocketAddr

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for bool

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for char

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for f32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for f64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for i8

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for i16

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for i32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for i64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for i128

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for isize

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for str

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for u8

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for u16

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for u32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for u64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for u128

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for ()

source§

impl Encode for usize

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for CString

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for String

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for Ipv4Addr

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for Ipv6Addr

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for SocketAddrV4

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for SocketAddrV6

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicBool

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicI8

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicI16

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicI32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicI64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicIsize

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicU8

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicU16

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicU32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicU64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for AtomicUsize

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for Duration

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for PathBuf

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for SystemTime

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroI8

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroI16

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroI32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroI64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroI128

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroIsize

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroU8

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroU16

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroU32

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroU64

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroU128

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl Encode for NonZeroUsize

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<'a> Encode for &'a CStr

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<'a, T> Encode for &'a T
where T: Encode + ?Sized,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<'cow, T> Encode for Cow<'cow, T>
where T: ToOwned + ?Sized, for<'a> &'a T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<A> Encode for (A,)
where A: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B> Encode for (A, B)
where A: Encode, B: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C> Encode for (A, B, C)
where A: Encode, B: Encode, C: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D> Encode for (A, B, C, D)
where A: Encode, B: Encode, C: Encode, D: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D, E> Encode for (A, B, C, D, E)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D, E, F> Encode for (A, B, C, D, E, F)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D, E, F, G> Encode for (A, B, C, D, E, F, G)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D, E, F, G, H> Encode for (A, B, C, D, E, F, G, H)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D, E, F, G, H, I> Encode for (A, B, C, D, E, F, G, H, I)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<A, B, C, D, E, F, G, H, I, J> Encode for (A, B, C, D, E, F, G, H, I, J)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

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)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode, K: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

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)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode, K: Encode, L: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

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)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode, K: Encode, L: Encode, M: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

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)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode, K: Encode, L: Encode, M: Encode, N: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

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)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode, K: Encode, L: Encode, M: Encode, N: Encode, O: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

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)
where A: Encode, B: Encode, C: Encode, D: Encode, E: Encode, F: Encode, G: Encode, H: Encode, I: Encode, J: Encode, K: Encode, L: Encode, M: Encode, N: Encode, O: Encode, P: Encode,

source§

fn encode<_E: Encoder>(&self, encoder: &mut _E) -> Result<(), EncodeError>

source§

impl<K, V> Encode for BTreeMap<K, V>
where K: Encode + Ord, V: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<K, V, S> Encode for HashMap<K, V, S>
where K: Encode, V: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Bound<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Option<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for [T]
where T: Encode + 'static,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Box<T>
where T: Encode + ?Sized,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for BinaryHeap<T>
where T: Encode + Ord,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for BTreeSet<T>
where T: Encode + Ord,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for VecDeque<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Rc<T>
where T: Encode + ?Sized,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Arc<T>
where T: Encode + ?Sized,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Vec<T>
where T: Encode + 'static,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Cell<T>
where T: Encode + Copy,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for RefCell<T>
where T: Encode + ?Sized,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for PhantomData<T>

source§

impl<T> Encode for Range<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for RangeInclusive<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for Mutex<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T> Encode for RwLock<T>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T, S> Encode for HashSet<T, S>
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T, U> Encode for Result<T, U>
where T: Encode, U: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

source§

impl<T, const N: usize> Encode for [T; N]
where T: Encode,

source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

Implementors§