Trait bincode::de::Decode

source ·
pub trait Decode: Sized {
    // Required method
    fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>;
}
Expand description

Trait that makes a type able to be decoded, akin to serde’s DeserializeOwned trait.

This trait should be implemented for types which do not have references to data in the reader. For types that contain e.g. &str and &[u8], implement BorrowDecode instead.

Whenever you implement Decode for your type, the base trait BorrowDecode is automatically implemented.

This trait will be automatically implemented if you enable the derive feature and add #[derive(bincode::Decode)] to your type. Note that if the type contains any lifetimes, BorrowDecode will be implemented instead.

§Implementing this trait manually

If you want to implement this trait for your type, the easiest way is to add a #[derive(bincode::Decode)], build and check your target/generated/bincode/ folder. This should generate a <Struct name>_Decode.rs file.

For this struct:

struct Entity {
    pub x: f32,
    pub y: f32,
}

It will look something like:

impl bincode::Decode for Entity {
    fn decode<D: bincode::de::Decoder>(
        decoder: &mut D,
    ) -> core::result::Result<Self, bincode::error::DecodeError> {
        Ok(Self {
            x: bincode::Decode::decode(decoder)?,
            y: bincode::Decode::decode(decoder)?,
        })
    }
}
impl<'de> bincode::BorrowDecode<'de> for Entity {
    fn borrow_decode<D: bincode::de::BorrowDecoder<'de>>(
        decoder: &mut D,
    ) -> core::result::Result<Self, bincode::error::DecodeError> {
        Ok(Self {
            x: bincode::BorrowDecode::borrow_decode(decoder)?,
            y: bincode::BorrowDecode::borrow_decode(decoder)?,
        })
    }
}

From here you can add/remove fields, or add custom logic.

To get specific integer types, you can use:

let x: u8 = bincode::Decode::decode(decoder)?;
let x = <u8 as bincode::Decode>::decode(decoder)?;

Required Methods§

source

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Decode for IpAddr

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for SocketAddr

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for bool

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for char

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for f32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for f64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for i8

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for i16

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for i32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for i64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for i128

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for isize

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for u8

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for u16

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for u32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for u64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for u128

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for ()

source§

impl Decode for usize

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for Box<str>

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for CString

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for String

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for Arc<str>

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for Ipv4Addr

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for Ipv6Addr

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for SocketAddrV4

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for SocketAddrV6

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicBool

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicI8

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicI16

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicI32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicI64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicIsize

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicU8

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicU16

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicU32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicU64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for AtomicUsize

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for Duration

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for PathBuf

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for SystemTime

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroI8

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroI16

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroI32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroI64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroI128

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroIsize

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroU8

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroU16

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroU32

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroU64

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroU128

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl Decode for NonZeroUsize

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<'cow, T> Decode for Cow<'cow, T>
where T: ToOwned + ?Sized, <T as ToOwned>::Owned: Decode,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> Decode for (A, B, C, D, E, F, G, H, I, J, K, L, M)
where A: Decode, B: Decode, C: Decode, D: Decode, E: Decode, F: Decode, G: Decode, H: Decode, I: Decode, J: Decode, K: Decode, L: Decode, M: Decode,

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> Decode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
where A: Decode, B: Decode, C: Decode, D: Decode, E: Decode, F: Decode, G: Decode, H: Decode, I: Decode, J: Decode, K: Decode, L: Decode, M: Decode, N: Decode,

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Decode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
where A: Decode, B: Decode, C: Decode, D: Decode, E: Decode, F: Decode, G: Decode, H: Decode, I: Decode, J: Decode, K: Decode, L: Decode, M: Decode, N: Decode, O: Decode,

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Decode for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
where A: Decode, B: Decode, C: Decode, D: Decode, E: Decode, F: Decode, G: Decode, H: Decode, I: Decode, J: Decode, K: Decode, L: Decode, M: Decode, N: Decode, O: Decode, P: Decode,

source§

fn decode<DE: Decoder>(decoder: &mut DE) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<K, V, S> Decode for HashMap<K, V, S>
where K: Decode + Eq + Hash, V: Decode, S: BuildHasher + Default,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T> Decode for Box<T>
where T: Decode,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T> Decode for Rc<T>
where T: Decode,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T> Decode for Arc<T>
where T: Decode,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T> Decode for Cell<T>
where T: Decode,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T> Decode for RefCell<T>
where T: Decode,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T> Decode for PhantomData<T>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T, S> Decode for HashSet<T, S>
where T: Decode + Eq + Hash, S: BuildHasher + Default,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

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

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

source§

impl<T, const N: usize> Decode for [T; N]
where T: Decode + Sized + 'static,

source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

Implementors§