Trait Decode
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§
fn decode(d: &mut Decoder<'b>, ctx: &mut C) -> Result<Self, Error>
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§
fn 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.
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§
§impl<'b, C> Decode<'b, C> for SocketAddr
Available on crate feature std only.
impl<'b, C> Decode<'b, C> for SocketAddr
std only.§impl<'b, C> Decode<'b, C> for SocketAddrV4
Available on crate feature std only.
impl<'b, C> Decode<'b, C> for SocketAddrV4
std only.§impl<'b, C> Decode<'b, C> for SocketAddrV6
Available on crate feature std only.
impl<'b, C> Decode<'b, C> for SocketAddrV6
std only.§impl<'b, C> Decode<'b, C> for AtomicBool
impl<'b, C> Decode<'b, C> for AtomicBool
§impl<'b, C> Decode<'b, C> for AtomicIsize
impl<'b, C> Decode<'b, C> for AtomicIsize
§impl<'b, C> Decode<'b, C> for AtomicUsize
impl<'b, C> Decode<'b, C> for AtomicUsize
§impl<'b, C> Decode<'b, C> for SystemTime
Available on crate feature std only.
impl<'b, C> Decode<'b, C> for SystemTime
std only.§impl<'b, C, T> Decode<'b, C> for Box<T>where
T: Decode<'b, C>,
Available on crate feature alloc only.
impl<'b, C, T> Decode<'b, C> for Box<T>where
T: Decode<'b, C>,
alloc only.§impl<'b, C, T> Decode<'b, C> for BinaryHeap<T>
Available on crate feature alloc only.
impl<'b, C, T> Decode<'b, C> for BinaryHeap<T>
alloc only.§impl<'b, C, T> Decode<'b, C> for LinkedList<T>where
T: Decode<'b, C>,
impl<'b, C, T> Decode<'b, C> for LinkedList<T>where
T: Decode<'b, C>,
§impl<'b, C, T> Decode<'b, C> for PhantomData<T>
impl<'b, C, T> Decode<'b, C> for PhantomData<T>
§impl<'b, C, T> Decode<'b, C> for RangeInclusive<T>where
T: Decode<'b, C>,
impl<'b, C, T> Decode<'b, C> for RangeInclusive<T>where
T: Decode<'b, C>,
§impl<'b, C, T> Decode<'b, C> for RangeToInclusive<T>where
T: Decode<'b, C>,
impl<'b, C, T> Decode<'b, C> for RangeToInclusive<T>where
T: Decode<'b, C>,
§impl<'b, Ctx, A, B, C, D> Decode<'b, Ctx> for (A, B, C, D)
impl<'b, Ctx, A, B, C, D> Decode<'b, Ctx> for (A, B, C, D)
§impl<'b, Ctx, A, B, C, D, E> Decode<'b, Ctx> for (A, B, C, D, E)
impl<'b, Ctx, A, B, C, D, E> Decode<'b, Ctx> for (A, B, C, D, E)
§impl<'b, Ctx, A, B, C, D, E, F> Decode<'b, Ctx> for (A, B, C, D, E, F)
impl<'b, Ctx, A, B, C, D, E, F> Decode<'b, Ctx> for (A, B, C, D, E, F)
§impl<'b, Ctx, A, B, C, D, E, F, G> Decode<'b, Ctx> for (A, B, C, D, E, F, G)
impl<'b, Ctx, A, B, C, D, E, F, G> Decode<'b, Ctx> for (A, B, C, D, E, F, G)
§impl<'b, Ctx, A, B, C, D, E, F, G, H> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H)
impl<'b, Ctx, A, B, C, D, E, F, G, H> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I)
impl<'b, Ctx, A, B, C, D, E, F, G, H, I> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J)
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K)
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M)
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)where
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>,
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)where
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>,
§impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)where
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>,
impl<'b, Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Decode<'b, Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)where
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>,
§impl<'bytes, Ctx, T1> Decode<'bytes, Ctx> for PseudoTransactionBody<T1>where
T1: Decode<'bytes, Ctx>,
impl<'bytes, Ctx, T1> Decode<'bytes, Ctx> for PseudoTransactionBody<T1>where
T1: Decode<'bytes, Ctx>,
§impl<'bytes, Ctx, T1> Decode<'bytes, Ctx> for PseudoTransactionBody<T1>where
T1: Decode<'bytes, Ctx>,
impl<'bytes, Ctx, T1> Decode<'bytes, Ctx> for PseudoTransactionBody<T1>where
T1: Decode<'bytes, Ctx>,
§impl<'bytes, Ctx, T1, T2, T3> Decode<'bytes, Ctx> for PseudoPostAlonzoTransactionOutput<T1, T2, T3>
impl<'bytes, Ctx, T1, T2, T3> Decode<'bytes, Ctx> for PseudoPostAlonzoTransactionOutput<T1, T2, T3>
Implementors§
impl<'a, 'b, C> Decode<'b, C> for &'a ByteSlicewhere
'b: 'a,
impl<'b, C> Decode<'b, C> for Token<'b>
impl<'b, C> Decode<'b, C> for cardano_sdk::cbor::data::Int
impl<'b, C> Decode<'b, C> for Tag
impl<'b, C, const N: u64, T> Decode<'b, C> for Tagged<N, T>where
T: Decode<'b, C>,
impl<'b, C, const N: usize> Decode<'b, C> for ByteArray<N>
impl<'bytes, Ctx> Decode<'bytes, Ctx> for Network
impl<'bytes, Ctx> Decode<'bytes, Ctx> for PlutusVersion
impl<'bytes, Ctx> Decode<'bytes, Ctx> for Hash28
impl<'bytes, Ctx> Decode<'bytes, Ctx> for Hash32
impl<'bytes, Ctx> Decode<'bytes, Ctx> for Credential
impl<'bytes, Ctx> Decode<'bytes, Ctx> for ExecutionUnits
impl<'bytes, Ctx> Decode<'bytes, Ctx> for cardano_sdk::NetworkId
impl<'bytes, Ctx> Decode<'bytes, Ctx> for cardano_sdk::RedeemerPointer
impl<'bytes, Ctx, const SIZE: usize> Decode<'bytes, Ctx> for cardano_sdk::Hash<SIZE>
impl<'d, C> Decode<'d, C> for Input
impl<'d, C> Decode<'d, C> for Output
impl<'d, C> Decode<'d, C> for cardano_sdk::PlutusData<'static>
impl<'d, C> Decode<'d, C> for Transaction<ReadyForSigning>
impl<'d, C> Decode<'d, C> for Transaction<Unknown>
impl<'d, C> Decode<'d, C> for cardano_sdk::Value<u64>
impl<C> Decode<'_, C> for ByteVec
alloc only.