Decode

Trait Decode 

Source
pub trait Decode: Sized {
    type Error;

    // Required method
    fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>;
}
Expand description

Denotes a type capable of being decoded.

This trait can be derived for custom types using the Decode derive macro.

Do remember that this macro assumes that the Encode trait has not been manually implemented (i.e. it must either be not implemented or derived). Breaking this promise is a logic error and can lead to failed decodings.

See also the decode module’s documentation on how to use decodings.

Required Associated Types§

Source

type Error

The type returned in case of error.

Required Methods§

Source

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Decodes an object from the provided input.

§Errors

If decoding fails due to e.g. an invalid byte sequence in the input, then an error should be returned.

§Panics

If input unexpectedly terminates before a full encoding was read, then this method should panic.

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 Decode for Infallible

Source§

type Error = Infallible

Source§

fn decode(_input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for c_void

Source§

type Error = Infallible

Source§

fn decode(_input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for IpAddr

Source§

type Error = EnumDecodeError<u8, <u8 as Decode>::Error, Infallible>

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for SocketAddr

Source§

type Error = EnumDecodeError<u8, <u8 as Decode>::Error, Infallible>

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for bool

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Lossily reinterprets a byte value as a boolean.

Whilst Encode::encode will only yield the values 0 and 1, this method clamps all values above 1.

Source§

type Error = BoolDecodeError

Source§

impl Decode for char

Source§

type Error = CharDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for f16

Available on crate feature f16 only.
Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for f32

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for f64

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for f128

Available on crate feature f128 only.
Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for i8

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for i16

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for i32

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for i64

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for i128

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for isize

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for u8

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for u16

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for u32

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for u64

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for u128

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for ()

Source§

type Error = Infallible

Source§

fn decode(_input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for usize

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for CString

Available on crate feature alloc only.
Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Decodes a byte slice from the input.

This implementation will always allocate one more byte than specified by the slice for the null terminator. Note that any null value already in the data will truncate the final string.

Source§

type Error = <Vec<u8> as Decode>::Error

Source§

impl Decode for String

Available on crate feature alloc only.
Source§

impl Decode for PhantomPinned

Source§

type Error = Infallible

Source§

fn decode(_input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for Ipv4Addr

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for Ipv6Addr

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for SocketAddrV4

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for SocketAddrV6

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<i8>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<i16>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<i32>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<i64>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<i128>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<isize>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<u8>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<u16>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<u32>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<u64>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<u128>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for NonZero<usize>

Source§

type Error = NonZeroDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for RangeFull

Source§

type Error = Infallible

Source§

fn decode(_input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicBool

Available on target_has_atomic="8" only.
Source§

type Error = <bool as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicI8

Available on target_has_atomic="8" only.
Source§

type Error = <i8 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicI16

Available on target_has_atomic="16" only.
Source§

type Error = <i16 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicI32

Available on target_has_atomic="32" only.
Source§

type Error = <i32 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicI64

Available on target_has_atomic="64" only.
Source§

type Error = <i64 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicIsize

Available on target_has_atomic="ptr" only.
Source§

type Error = <isize as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicU8

Available on target_has_atomic="8" only.
Source§

type Error = <u8 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicU16

Available on target_has_atomic="16" only.
Source§

type Error = <u16 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicU32

Available on target_has_atomic="32" only.
Source§

type Error = <u32 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicU64

Available on target_has_atomic="64" only.
Source§

type Error = <u64 as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for AtomicUsize

Available on target_has_atomic="ptr" only.
Source§

type Error = <usize as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for Duration

Source§

type Error = Infallible

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for OsString

Available on crate feature std only.
Source§

type Error = <String as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl Decode for SystemTime

Available on crate feature std only.
Source§

type Error = SystemTimeDecodeError

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

impl<T> Decode for PhantomData<T>

Source§

type Error = Infallible

Source§

fn decode(_input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T, B> Decode for Cow<'_, B>
where T: DecodeBorrowed<B>, B: ToOwned<Owned = T> + ?Sized,

Available on crate feature alloc only.
Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T, E, Err> Decode for Result<T, E>
where T: Decode<Error = Err>, E: Decode<Error: Into<Err>>,

Source§

type Error = EnumDecodeError<bool, <bool as Decode>::Error, Err>

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Available on crate feature alloc only.
Source§

type Error = <Vec<T> as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Source§

type Error = EnumDecodeError<u8, <u8 as Decode>::Error, <T as Decode>::Error>

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Source§

type Error = EnumDecodeError<bool, <bool as Decode>::Error, <T as Decode>::Error>

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for (T₁, T₂, …, Tₙ)

Implemented for tuples with up to twelve members.

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Available on crate feature alloc only.
Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for LinkedList<T>

Available on crate feature alloc only.
Source§

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

Available on crate feature alloc only.
Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for Weak<T>

Available on crate feature alloc only.
Source§

type Error = <Option<Rc<T>> as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Available on crate feature alloc and target_has_atomic="ptr" only.
Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for Weak<T>

Available on crate feature alloc and target_has_atomic="ptr" only.
Source§

type Error = <Option<Arc<T>> as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for Vec<T>

Available on crate feature alloc only.
Source§

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

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for UnsafeCell<T>

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for Saturating<T>

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for Wrapping<T>

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for RangeFrom<T>

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for RangeTo<T>

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

impl<T: Decode> Decode for RangeToInclusive<T>

Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Available on crate feature std only.
Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Available on crate feature std only.
Source§

type Error = <T as Decode>::Error

Source§

fn decode(input: &mut Input<'_>) -> Result<Self, Self::Error>

Source§

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

Implementors§