Trait minicbor::decode::Decode[][src]

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

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

A type that can be decoded from CBOR.

Required methods

Decode a value using the given Decoder.

Provided methods

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.

Implementations on Foreign Types

Implementors