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

A structure for implementing serialization to JSON.

Implementations§

source§

impl<'a> Encoder<'a>

source

pub fn new_pretty(writer: &'a mut dyn Write) -> Encoder<'a>

Creates a new encoder whose output will be written in human-readable JSON to the specified writer

source

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

Creates a new encoder whose output will be written in compact JSON to the specified writer

source

pub fn set_indent(&mut self, new_indent: u32) -> Result<(), ()>

Set the number of spaces to indent for each level. This is safe to set during encoding.

Trait Implementations§

source§

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

§

type Error = EncoderError

The error type for method results.
source§

fn emit_nil(&mut self) -> EncodeResult<()>

Emit a nil value. Read more
source§

fn emit_usize(&mut self, v: usize) -> EncodeResult<()>

Emit a usize value.
source§

fn emit_u64(&mut self, v: u64) -> EncodeResult<()>

Emit a u64 value.
source§

fn emit_u32(&mut self, v: u32) -> EncodeResult<()>

Emit a u32 value.
source§

fn emit_u16(&mut self, v: u16) -> EncodeResult<()>

Emit a u16 value.
source§

fn emit_u8(&mut self, v: u8) -> EncodeResult<()>

Emit a u8 value.
source§

fn emit_isize(&mut self, v: isize) -> EncodeResult<()>

Emit a isize value.
source§

fn emit_i64(&mut self, v: i64) -> EncodeResult<()>

Emit a i64 value.
source§

fn emit_i32(&mut self, v: i32) -> EncodeResult<()>

Emit a i32 value.
source§

fn emit_i16(&mut self, v: i16) -> EncodeResult<()>

Emit a i16 value.
source§

fn emit_i8(&mut self, v: i8) -> EncodeResult<()>

Emit a i8 value.
source§

fn emit_bool(&mut self, v: bool) -> EncodeResult<()>

Emit a bool value. Read more
source§

fn emit_f64(&mut self, v: f64) -> EncodeResult<()>

Emit a f64 value.
source§

fn emit_f32(&mut self, v: f32) -> EncodeResult<()>

Emit a f32 value.
source§

fn emit_char(&mut self, v: char) -> EncodeResult<()>

Emit a char value. Read more
source§

fn emit_str(&mut self, v: &str) -> EncodeResult<()>

Emit a string value.
source§

fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit an enumeration value. Read more
source§

fn emit_enum_variant<F>( &mut self, name: &str, _id: usize, cnt: usize, f: F ) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit a enumeration variant value with no or unnamed data. Read more
source§

fn emit_enum_variant_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit an unnamed data item for an enumeration variant. Read more
source§

fn emit_enum_struct_variant<F>( &mut self, name: &str, id: usize, cnt: usize, f: F ) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_enum_struct_variant_field<F>( &mut self, _: &str, idx: usize, f: F ) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_struct<F>(&mut self, _: &str, len: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit a struct value. Read more
source§

fn emit_struct_field<F>( &mut self, name: &str, idx: usize, f: F ) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_tuple<F>(&mut self, len: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit a tuple value. Read more
source§

fn emit_tuple_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_tuple_struct<F>( &mut self, _: &str, len: usize, f: F ) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit a tuple struct value. Read more
source§

fn emit_tuple_struct_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_option<F>(&mut self, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit an optional value. Read more
source§

fn emit_option_none(&mut self) -> EncodeResult<()>

Emit the None optional value. Read more
source§

fn emit_option_some<F>(&mut self, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_seq<F>(&mut self, len: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit a sequence of values. Read more
source§

fn emit_seq_elt<F>(&mut self, idx: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

Emit an element in a sequence. Read more
source§

fn emit_map<F>(&mut self, len: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_map_elt_key<F>(&mut self, idx: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> EncodeResult<()>where F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<S> EncoderHelpers for Swhere 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 Twhere 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 Twhere 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 Twhere 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.