minicbor::decode

Trait Decode

Source
pub trait Decode<'b, C>: Sized {
    // Required method
    fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>;

    // Provided method
    fn nil() -> Option<Self> { ... }
}
Expand description

A type that can be decoded from CBOR.

Required Methods§

Source

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Decode a value using the given Decoder.

In addition to the decoder a user provided decoding context is given as another parameter. Most implementations of this trait do not need a decoding context and should be completely generic in the context type. In cases where a context is needed and the Decode impl type is meant to be combined with other types that require a different context type, it is preferrable to constrain the context type variable C with a trait bound instead of fixing the type.

Provided Methods§

Source

fn nil() -> Option<Self>

If possible, return a nil value of Self.

This method is primarily used by minicbor-derive and allows creating a special value denoting the absence of a “real” value if no CBOR value is present. The canonical example of a type where this is sensible is the Option type, whose Decode::nil method would return Some(None).

With the exception of Option<_> all types T are considered mandatory by default, i.e. T::nil() returns None. Missing values of T therefore cause decoding errors in derived Decode implementations.

NB: A type implementing Decode with an overriden Decode::nil method should also override Encode::is_nil if it implements Encode at all.

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<'a, 'b: 'a, C> Decode<'b, C> for &'a str

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'a, 'b: 'a, C> Decode<'b, C> for &'a CStr

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for bool

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for char

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for f32

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for f64

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for i8

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for i16

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for i32

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for i64

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for isize

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for u8

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for u16

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for u32

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for u64

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for ()

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for usize

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicBool

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicI8

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicI16

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicI32

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicIsize

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicU8

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicU16

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicU32

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for AtomicUsize

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for Duration

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroI8

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroI16

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroI32

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroI64

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroU8

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroU16

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroU32

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C> Decode<'b, C> for NonZeroU64

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T> Decode<'b, C> for PhantomData<T>

Source§

fn decode(d: &mut Decoder<'b>, _: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T, E> Decode<'b, C> for Result<T, E>
where T: Decode<'b, C>, E: Decode<'b, C>,

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for Bound<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for Option<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

fn nil() -> Option<Self>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for Cell<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for RefCell<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for Wrapping<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for Range<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for RangeFrom<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for RangeInclusive<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for RangeTo<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, C, T: Decode<'b, C>> Decode<'b, C> for RangeToInclusive<T>

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>

Source§

impl<'b, Ctx, A: Decode<'b, Ctx>> Decode<'b, Ctx> for (A,)

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

impl<'b, Ctx, A: Decode<'b, Ctx>, B: Decode<'b, Ctx>> Decode<'b, Ctx> for (A, B)

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

impl<'b, Ctx, A: Decode<'b, Ctx>, B: Decode<'b, Ctx>, C: Decode<'b, Ctx>> Decode<'b, Ctx> for (A, B, C)

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

impl<'b, Ctx, A: Decode<'b, Ctx>, B: Decode<'b, Ctx>, C: Decode<'b, Ctx>, D: Decode<'b, Ctx>> Decode<'b, Ctx> for (A, B, C, D)

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

impl<'b, Ctx, A: Decode<'b, Ctx>, B: Decode<'b, Ctx>, C: Decode<'b, Ctx>, D: Decode<'b, Ctx>, E: Decode<'b, Ctx>> Decode<'b, Ctx> for (A, B, C, D, E)

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

impl<'b, Ctx, A: Decode<'b, Ctx>, B: Decode<'b, Ctx>, C: Decode<'b, Ctx>, D: Decode<'b, Ctx>, E: Decode<'b, Ctx>, F: Decode<'b, Ctx>> Decode<'b, Ctx> for (A, B, C, D, E, F)

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Source§

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

Source§

fn decode(d: &mut Decoder<'b>, ctx: &mut Ctx) -> Result<Self, Error>

Implementors§

Source§

impl<'a, 'b: 'a, C> Decode<'b, C> for &'a ByteSlice

Source§

impl<'b, C> Decode<'b, C> for Int

Source§

impl<'b, C> Decode<'b, C> for Tag

Source§

impl<'b, C, const N: u64, T: Decode<'b, C>> Decode<'b, C> for Tagged<N, T>

Source§

impl<'b, C, const N: usize> Decode<'b, C> for ByteArray<N>