Trait minicbor::encode::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.

Implementations on Foreign Types§

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>> 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<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<C> Encode<C> for Ipv4Addr

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &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> 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 NonZeroI64

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

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<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<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, T: Encode<C>> Encode<C> for VecDeque<T>

source§

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

source§

impl<C> Encode<C> for CString

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C ) -> 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<C, K, V> Encode<C> for BTreeMap<K, V>where K: Encode<C> + Eq + Ord, V: Encode<C>,

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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 i64

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &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, T: Encode<C>> Encode<C> for BTreeSet<T>

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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<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<C> Encode<C> for SystemTime

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> 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 SocketAddrV4

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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<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<C> Encode<C> for AtomicI64

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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, 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>, 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<C, T, S> Encode<C> for HashSet<T, S>where T: Encode<C>, S: BuildHasher,

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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, 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<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<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> 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 AtomicBool

source§

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

source§

impl<C> Encode<C> for SocketAddr

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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 isize

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, K, V, S> Encode<C> for HashMap<K, V, S>where K: Encode<C> + Eq + Hash, V: Encode<C>, S: BuildHasher,

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C ) -> 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<C, T: Encode<C>> Encode<C> for LinkedList<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 RangeTo<T>

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 CStr

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 NonZeroU8

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> Encode<C> for Path

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &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 [T]

source§

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

source§

impl<C, T> Encode<C> for Cow<'_, T>where T: Encode<C> + ToOwned + ?Sized,

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &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 Duration

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<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<C> Encode<C> for str

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &mut C ) -> 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<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 NonZeroI16

source§

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

source§

impl<C> Encode<C> for String

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &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 AtomicU64

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<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>, 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>> 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<C, T: Encode<C>> Encode<C> for BinaryHeap<T>

source§

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

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 PathBuf

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C ) -> 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<C> Encode<C> for f64

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &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<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<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, T: Encode<C> + ?Sized> Encode<C> for Box<T>

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C ) -> 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<C, T: Encode<C>> Encode<C> for Vec<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> Encode<C> for Ipv6Addr

source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, _: &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 IpAddr

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 SocketAddrV6

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

Implementors§

source§

impl<C> Encode<C> for ByteSlice

source§

impl<C> Encode<C> for ByteVec

source§

impl<C> Encode<C> for Int

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: usize> Encode<C> for ByteArray<N>