Trait Encode
pub trait Encode<C> {
// Required method
fn encode<W>(
&self,
e: &mut Encoder<W>,
ctx: &mut C,
) -> Result<(), Error<<W as Write>::Error>>
where W: Write;
// Provided method
fn is_nil(&self) -> bool { ... }
}Expand description
A type that can be encoded to CBOR.
If this type’s CBOR encoding is meant to be decoded by Decode impls
derived with [minicbor_derive] it is advisable to only produce a
single CBOR data item. Tagging, maps or arrays can and should be used
for multiple values.
Required Methods§
fn encode<W>(
&self,
e: &mut Encoder<W>,
ctx: &mut C,
) -> Result<(), Error<<W as Write>::Error>>where
W: Write,
fn encode<W>(
&self,
e: &mut Encoder<W>,
ctx: &mut C,
) -> Result<(), Error<<W as Write>::Error>>where
W: Write,
Encode a value of this type using the given Encoder.
In addition to the encoder a user provided encoding context is given
as another parameter. Most implementations of this trait do not need an
encoding context and should be completely generic in the context
type. In cases where a context is needed and the Encode 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 is_nil(&self) -> bool
fn is_nil(&self) -> bool
Is this value of Self a nil value?
This method is primarily used by minicbor-derive.
Some types have a special value to denote the concept of “nothing”, aka
nil. An example is the Option type with its None value. This
method–if overriden–allows checking if a value is such a special nil
value.
NB: A type implementing Encode with an overriden Encode::is_nil
method should also override Decode::nil if it implements Decode
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<C> Encode<C> for SocketAddr
Available on crate feature std only.
impl<C> Encode<C> for SocketAddr
std only.§impl<C> Encode<C> for SocketAddrV4
Available on crate feature std only.
impl<C> Encode<C> for SocketAddrV4
std only.§impl<C> Encode<C> for SocketAddrV6
Available on crate feature std only.
impl<C> Encode<C> for SocketAddrV6
std only.§impl<C> Encode<C> for AtomicBool
impl<C> Encode<C> for AtomicBool
§impl<C> Encode<C> for AtomicIsize
impl<C> Encode<C> for AtomicIsize
§impl<C> Encode<C> for AtomicUsize
impl<C> Encode<C> for AtomicUsize
§impl<C> Encode<C> for SystemTime
Available on crate feature std only.
impl<C> Encode<C> for SystemTime
std only.§impl<C, T> Encode<C> for BinaryHeap<T>where
T: Encode<C>,
impl<C, T> Encode<C> for BinaryHeap<T>where
T: Encode<C>,
§impl<C, T> Encode<C> for LinkedList<T>where
T: Encode<C>,
impl<C, T> Encode<C> for LinkedList<T>where
T: Encode<C>,
§impl<C, T> Encode<C> for PhantomData<T>
impl<C, T> Encode<C> for PhantomData<T>
§impl<C, T> Encode<C> for RangeInclusive<T>where
T: Encode<C>,
impl<C, T> Encode<C> for RangeInclusive<T>where
T: Encode<C>,
§impl<C, T> Encode<C> for RangeToInclusive<T>where
T: Encode<C>,
impl<C, T> Encode<C> for RangeToInclusive<T>where
T: Encode<C>,
§impl<C, T, S> Encode<C> for HashSet<T, S>where
T: Encode<C>,
S: BuildHasher,
Available on crate feature std only.
impl<C, T, S> Encode<C> for HashSet<T, S>where
T: Encode<C>,
S: BuildHasher,
std only.§impl<Ctx, A, B, C, D> Encode<Ctx> for (A, B, C, D)
impl<Ctx, A, B, C, D> Encode<Ctx> for (A, B, C, D)
§impl<Ctx, A, B, C, D, E> Encode<Ctx> for (A, B, C, D, E)
impl<Ctx, A, B, C, D, E> Encode<Ctx> for (A, B, C, D, E)
§impl<Ctx, A, B, C, D, E, F> Encode<Ctx> for (A, B, C, D, E, F)
impl<Ctx, A, B, C, D, E, F> Encode<Ctx> for (A, B, C, D, E, F)
§impl<Ctx, A, B, C, D, E, F, G> Encode<Ctx> for (A, B, C, D, E, F, G)
impl<Ctx, A, B, C, D, E, F, G> Encode<Ctx> for (A, B, C, D, E, F, G)
§impl<Ctx, A, B, C, D, E, F, G, H> Encode<Ctx> for (A, B, C, D, E, F, G, H)
impl<Ctx, A, B, C, D, E, F, G, H> Encode<Ctx> for (A, B, C, D, E, F, G, H)
§impl<Ctx, A, B, C, D, E, F, G, H, I> Encode<Ctx> for (A, B, C, D, E, F, G, H, I)
impl<Ctx, A, B, C, D, E, F, G, H, I> Encode<Ctx> for (A, B, C, D, E, F, G, H, I)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J)
impl<Ctx, A, B, C, D, E, F, G, H, I, J> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J, K> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K)
impl<Ctx, A, B, C, D, E, F, G, H, I, J, K> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M)
impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
§impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
impl<Ctx, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
Implementors§
impl<'b, C> Encode<C> for Token<'b>
impl<C> Encode<C> for IanaTag
impl<C> Encode<C> for Input
impl<C> Encode<C> for Output
impl<C> Encode<C> for cardano_sdk::PlutusData<'_>
impl<C> Encode<C> for cardano_sdk::Value<u64>
impl<C> Encode<C> for ByteSlice
impl<C> Encode<C> for ByteVec
alloc only.