minicbor::encode

Trait Encode

Source
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§

Source

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§

Source

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 bool

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for char

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for f32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for f64

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for i8

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for i16

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for i32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for i64

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for isize

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for str

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for u8

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for u16

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for u32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for u64

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for ()

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for usize

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for CStr

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicBool

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicI8

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicI16

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicI32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicIsize

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicU8

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicU16

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicU32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for AtomicUsize

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for Duration

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroI8

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroI16

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroI32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroI64

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroU8

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroU16

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroU32

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C> Encode<C> for NonZeroU64

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T> Encode<C> for PhantomData<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C> + Copy> Encode<C> for Cell<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C> + ?Sized> Encode<C> for &T

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C> + ?Sized> Encode<C> for &mut T

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for Bound<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for Option<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

fn is_nil(&self) -> bool

Source§

impl<C, T: Encode<C>> Encode<C> for [T]

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for RefCell<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for Wrapping<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for Range<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for RangeFrom<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for RangeInclusive<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for RangeTo<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>> Encode<C> for RangeToInclusive<T>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>, E: Encode<C>> Encode<C> for Result<T, E>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<C, T: Encode<C>, const N: usize> Encode<C> for [T; N]

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Source§

impl<Ctx, A: Encode<Ctx>> Encode<Ctx> for (A,)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

Source§

impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>> Encode<Ctx> for (A, B)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

Source§

impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>> Encode<Ctx> for (A, B, C)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

Source§

impl<Ctx, A: Encode<Ctx>, B: Encode<Ctx>, C: Encode<Ctx>, D: Encode<Ctx>> Encode<Ctx> for (A, B, C, D)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

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)

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut Ctx, ) -> Result<(), Error<W::Error>>

Implementors§

Source§

impl<C> Encode<C> for IanaTag

Source§

impl<C> Encode<C> for ByteSlice

Source§

impl<C> Encode<C> for Int

Source§

impl<C> Encode<C> for Tag

Source§

impl<C, I, K, V> Encode<C> for MapIter<I>
where I: Iterator<Item = (K, V)> + Clone, K: Encode<C>, V: Encode<C>,

Source§

impl<C, I, T> Encode<C> for ArrayIter<I>
where I: Iterator<Item = T> + Clone, T: Encode<C>,

Source§

impl<C, const N: u64, T: Encode<C>> Encode<C> for Tagged<N, T>

Source§

impl<C, const N: usize> Encode<C> for ByteArray<N>