Struct minicbor::encode::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 into_inner(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 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 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(&mut self, x: Tag) -> 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> AsRef<W> for Encoder<W>

source§

fn as_ref(&self) -> &W

Converts this type into a shared reference of the (usually inferred) input type.
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§

default 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.