pub trait Encode<C> {
// Required method
fn encode<W: Write>(
&self,
e: &mut Encoder<W>,
ctx: &mut C,
) -> Result<(), Error<W::Error>>;
// 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§
Sourcefn encode<W: Write>(
&self,
e: &mut Encoder<W>,
ctx: &mut C,
) -> Result<(), Error<W::Error>>
fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>
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§
Sourcefn 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§
Source§impl<C> Encode<C> for SocketAddr
Available on crate feature std only.
impl<C> Encode<C> for SocketAddr
std only.Source§impl<C> Encode<C> for SocketAddrV4
Available on crate feature std only.
impl<C> Encode<C> for SocketAddrV4
std only.Source§impl<C> Encode<C> for SocketAddrV6
Available on crate feature std only.
impl<C> Encode<C> for SocketAddrV6
std only.Source§impl<C> Encode<C> for AtomicBool
impl<C> Encode<C> for AtomicBool
Source§impl<C> Encode<C> for AtomicIsize
impl<C> Encode<C> for AtomicIsize
Source§impl<C> Encode<C> for AtomicUsize
impl<C> Encode<C> for AtomicUsize
Source§impl<C> Encode<C> for SystemTime
Available on crate feature std only.
impl<C> Encode<C> for SystemTime
std only.Source§impl<C> Encode<C> for NonZeroI16
impl<C> Encode<C> for NonZeroI16
Source§impl<C> Encode<C> for NonZeroI32
impl<C> Encode<C> for NonZeroI32
Source§impl<C> Encode<C> for NonZeroI64
impl<C> Encode<C> for NonZeroI64
Source§impl<C> Encode<C> for NonZeroIsize
impl<C> Encode<C> for NonZeroIsize
Source§impl<C> Encode<C> for NonZeroU16
impl<C> Encode<C> for NonZeroU16
Source§impl<C> Encode<C> for NonZeroU32
impl<C> Encode<C> for NonZeroU32
Source§impl<C> Encode<C> for NonZeroU64
impl<C> Encode<C> for NonZeroU64
Source§impl<C> Encode<C> for NonZeroUsize
impl<C> Encode<C> for NonZeroUsize
Source§impl<C, T> Encode<C> for PhantomData<T>
impl<C, T> Encode<C> for PhantomData<T>
Source§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.Source§impl<C, T: Encode<C>> Encode<C> for BinaryHeap<T>
impl<C, T: Encode<C>> Encode<C> for BinaryHeap<T>
Source§impl<C, T: Encode<C>> Encode<C> for LinkedList<T>
impl<C, T: Encode<C>> Encode<C> for LinkedList<T>
Source§impl<C, T: Encode<C>> Encode<C> for RangeInclusive<T>
impl<C, T: Encode<C>> Encode<C> for RangeInclusive<T>
Source§impl<C, T: Encode<C>> Encode<C> for RangeToInclusive<T>
impl<C, T: Encode<C>> Encode<C> for RangeToInclusive<T>
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>> Encode<Ctx> for (A, B, C, D)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>> Encode<Ctx> for (A, B, C, D)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>, N: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>, N: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>, N: Encode<Ctx>, O: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>, N: Encode<Ctx>, O: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)
Source§impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>, N: Encode<Ctx>, O: Encode<Ctx>, P: Encode<Ctx>> Encode<Ctx> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>, E: Encode<Ctx>, F: Encode<Ctx>, G: Encode<Ctx>, H: Encode<Ctx>, I: Encode<Ctx>, J: Encode<Ctx>, K: Encode<Ctx>, L: Encode<Ctx>, M: Encode<Ctx>, N: Encode<Ctx>, O: Encode<Ctx>, P: Encode<Ctx>> 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 ByteSlice
impl<C> Encode<C> for ByteVec
alloc only.