pub trait Decode<'b>: Sized {
// Required method
fn decode(d: &mut Decoder<'b>) -> Result<Self, Error>;
// Provided method
fn nil() -> Option<Self> { ... }
}
Expand description
A type that can be decoded from CBOR.
Required Methods§
Provided Methods§
sourcefn nil() -> Option<Self>
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.
Object Safety§
This trait is not object safe.