Struct Encoder

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

Represents MessagePack serialization implementation.

§Note

MessagePack has no specification about how to encode variant types. Thus we are free to do whatever we want, so the given chose may be not ideal for you.

Every Rust variant value can be represented as a tuple of index and a value.

All instances of ErrorKind::Interrupted are handled by this function and the underlying operation is retried.

Implementations§

Source§

impl<'a> Encoder<'a>

Source

pub fn new(wr: &'a mut dyn Write) -> Encoder<'a>

Creates a new MessagePack encoder whose output will be written to the writer specified.

Trait Implementations§

Source§

impl<'a> Encoder for Encoder<'a>

Source§

fn emit_enum<F>(&mut self, _name: &str, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Encodes and attempts to write the enum value into the Write.

Currently we encode variant types as a tuple of id with array of args, like: [id, [args…]]

Source§

fn emit_enum_variant<F>( &mut self, _name: &str, id: usize, len: usize, f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Encodes and attempts to write a concrete variant value.

Source§

fn emit_enum_variant_arg<F>(&mut self, _idx: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Encodes and attempts to write a concrete variant value arguments.

Source§

type Error = ValueWriteError

The error type for method results.
Source§

fn emit_nil(&mut self) -> Result<(), Error>

Emit a nil value. Read more
Source§

fn emit_bool(&mut self, val: bool) -> Result<(), Error>

Emit a bool value. Read more
Source§

fn emit_u8(&mut self, val: u8) -> Result<(), Error>

Emit a u8 value.
Source§

fn emit_u16(&mut self, val: u16) -> Result<(), Error>

Emit a u16 value.
Source§

fn emit_u32(&mut self, val: u32) -> Result<(), Error>

Emit a u32 value.
Source§

fn emit_u64(&mut self, val: u64) -> Result<(), Error>

Emit a u64 value.
Source§

fn emit_usize(&mut self, val: usize) -> Result<(), Error>

Emit a usize value.
Source§

fn emit_i8(&mut self, val: i8) -> Result<(), Error>

Emit a i8 value.
Source§

fn emit_i16(&mut self, val: i16) -> Result<(), Error>

Emit a i16 value.
Source§

fn emit_i32(&mut self, val: i32) -> Result<(), Error>

Emit a i32 value.
Source§

fn emit_i64(&mut self, val: i64) -> Result<(), Error>

Emit a i64 value.
Source§

fn emit_isize(&mut self, val: isize) -> Result<(), Error>

Emit a isize value.
Source§

fn emit_f32(&mut self, val: f32) -> Result<(), Error>

Emit a f32 value.
Source§

fn emit_f64(&mut self, val: f64) -> Result<(), Error>

Emit a f64 value.
Source§

fn emit_char(&mut self, val: char) -> Result<(), Error>

Emit a char value. Read more
Source§

fn emit_str(&mut self, val: &str) -> Result<(), Error>

Emit a string value.
Source§

fn emit_enum_struct_variant<F>( &mut self, _name: &str, _id: usize, _len: usize, _f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a enumeration variant value with no or named data. Read more
Source§

fn emit_enum_struct_variant_field<F>( &mut self, _name: &str, _idx: usize, _f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a named data item for an enumeration variant. Read more
Source§

fn emit_struct<F>(&mut self, _name: &str, len: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a struct value. Read more
Source§

fn emit_struct_field<F>( &mut self, _name: &str, _idx: usize, f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a field item for a struct. Read more
Source§

fn emit_tuple<F>(&mut self, len: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a tuple value. Read more
Source§

fn emit_tuple_arg<F>(&mut self, _idx: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a data item for a tuple. Read more
Source§

fn emit_tuple_struct<F>( &mut self, _name: &str, len: usize, f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a tuple struct value. Read more
Source§

fn emit_tuple_struct_arg<F>(&mut self, _idx: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a data item for a tuple struct. Read more
Source§

fn emit_option<F>(&mut self, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit an optional value. Read more
Source§

fn emit_option_none(&mut self) -> Result<(), Error>

Emit the None optional value. Read more
Source§

fn emit_option_some<F>(&mut self, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit the Some(x) optional value. Read more
Source§

fn emit_seq<F>(&mut self, len: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit a sequence of values. Read more
Source§

fn emit_seq_elt<F>(&mut self, _idx: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit an element in a sequence. Read more
Source§

fn emit_map<F>(&mut self, len: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit an associative container (map). Read more
Source§

fn emit_map_elt_key<F>(&mut self, _idx: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit the key for an entry in a map. Read more
Source§

fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

Emit the value for an entry in a map. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Encoder<'a>

§

impl<'a> !RefUnwindSafe for Encoder<'a>

§

impl<'a> !Send for Encoder<'a>

§

impl<'a> !Sync for Encoder<'a>

§

impl<'a> Unpin for Encoder<'a>

§

impl<'a> !UnwindSafe for Encoder<'a>

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<S> EncoderHelpers for S
where S: Encoder,

Source§

fn emit_from_vec<T, F>( &mut self, v: &[T], f: F, ) -> Result<(), <S as Encoder>::Error>
where F: FnMut(&mut S, &T) -> Result<(), <S as Encoder>::Error>,

Emit a vector as a sequence. 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.