minicbor::encode

Struct Encoder

Source
pub struct Encoder<W> { /* private fields */ }
Expand description

A non-allocating CBOR encoder writing encoded bytes to the given Write sink.

Implementations§

Source§

impl<W: Write> Encoder<W>

Source

pub fn new(writer: W) -> Encoder<W>

Construct an Encoder that writes to the given Write sink.

Source

pub fn writer(&self) -> &W

Access the inner writer.

Source

pub fn writer_mut(&mut self) -> &mut W

Get mutable access to the inner writer.

Source

pub fn into_writer(self) -> W

Get back the Write impl.

Source

pub fn encode<T: Encode<()>>( &mut self, x: T, ) -> Result<&mut Self, Error<W::Error>>

Encode any type that implements Encode.

Source

pub fn encode_with<C, T: Encode<C>>( &mut self, x: T, ctx: &mut C, ) -> Result<&mut Self, Error<W::Error>>

Encode any type that implements Encode.

Source

pub fn u8(&mut self, x: u8) -> Result<&mut Self, Error<W::Error>>

Encode a u8 value.

Source

pub fn i8(&mut self, x: i8) -> Result<&mut Self, Error<W::Error>>

Encode an i8 value.

Source

pub fn u16(&mut self, x: u16) -> Result<&mut Self, Error<W::Error>>

Encode a u16 value.

Source

pub fn i16(&mut self, x: i16) -> Result<&mut Self, Error<W::Error>>

Encode an i16 value.

Source

pub fn u32(&mut self, x: u32) -> Result<&mut Self, Error<W::Error>>

Encode a u32 value.

Source

pub fn i32(&mut self, x: i32) -> Result<&mut Self, Error<W::Error>>

Encode an i32 value.

Source

pub fn u64(&mut self, x: u64) -> Result<&mut Self, Error<W::Error>>

Encode a u64 value.

Source

pub fn i64(&mut self, x: i64) -> Result<&mut Self, Error<W::Error>>

Encode an i64 value.

Source

pub fn int(&mut self, x: Int) -> Result<&mut Self, Error<W::Error>>

Encode a CBOR integer.

See Int for details regarding the value range of CBOR integers.

Source

pub fn null(&mut self) -> Result<&mut Self, Error<W::Error>>

Encode a CBOR null value.

Source

pub fn undefined(&mut self) -> Result<&mut Self, Error<W::Error>>

Encode a CBOR undefined value.

Source

pub fn simple(&mut self, x: u8) -> Result<&mut Self, Error<W::Error>>

Encode a CBOR simple value.

Source

pub fn f32(&mut self, x: f32) -> Result<&mut Self, Error<W::Error>>

Encode an f32 value.

Source

pub fn f64(&mut self, x: f64) -> Result<&mut Self, Error<W::Error>>

Encode an f64 value.

Source

pub fn bool(&mut self, x: bool) -> Result<&mut Self, Error<W::Error>>

Encode a bool value.

Source

pub fn char(&mut self, x: char) -> Result<&mut Self, Error<W::Error>>

Encode a char value.

Source

pub fn tag<T: Into<Tag>>(&mut self, x: T) -> Result<&mut Self, Error<W::Error>>

Encode a CBOR tag.

Source

pub fn bytes(&mut self, x: &[u8]) -> Result<&mut Self, Error<W::Error>>

Encode a byte slice.

Source

pub fn str(&mut self, x: &str) -> Result<&mut Self, Error<W::Error>>

Encode a string slice.

Source

pub fn array(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>

Begin encoding an array with len elements.

Source

pub fn map(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>

Begin encoding a map with len entries.

Source

pub fn begin_array(&mut self) -> Result<&mut Self, Error<W::Error>>

Begin encoding an array of unknown size.

Use Encoder::end to terminate the array.

Source

pub fn begin_bytes(&mut self) -> Result<&mut Self, Error<W::Error>>

Begin encoding an indefinite number of byte slices.

Use Encoder::end to terminate.

Source

pub fn begin_map(&mut self) -> Result<&mut Self, Error<W::Error>>

Begin encoding a map of unknown size.

Use Encoder::end to terminate the map.

Source

pub fn begin_str(&mut self) -> Result<&mut Self, Error<W::Error>>

Begin encoding an indefinite number of string slices.

Use Encoder::end to terminate.

Source

pub fn end(&mut self) -> Result<&mut Self, Error<W::Error>>

Terminate an indefinite collection.

Source

pub fn ok(&mut self) -> Result<(), Error<W::Error>>

Syntactic sugar for Ok(()).

Trait Implementations§

Source§

impl<W: Clone> Clone for Encoder<W>

Source§

fn clone(&self) -> Encoder<W>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<W: Debug> Debug for Encoder<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Encoder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Encoder<W>
where W: RefUnwindSafe,

§

impl<W> Send for Encoder<W>
where W: Send,

§

impl<W> Sync for Encoder<W>
where W: Sync,

§

impl<W> Unpin for Encoder<W>
where W: Unpin,

§

impl<W> UnwindSafe for Encoder<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.