[go: up one dir, main page]

Struct toml::Encoder

source ·
pub struct Encoder {
    pub toml: Table,
    /* private fields */
}
Expand description

A structure to transform Rust values into TOML values.

This encoder implements the serialization Encoder interface, allowing Encodable rust types to be fed into the encoder. The output of this encoder is a TOML Table structure. The resulting TOML can be stringified if necessary.

§Example

extern crate rustc_serialize;
extern crate toml;

use toml::{Encoder, Value};
use rustc_serialize::Encodable;

#[derive(RustcEncodable)]
struct MyStruct { foo: isize, bar: String }
let my_struct = MyStruct { foo: 4, bar: "hello!".to_string() };

let mut e = Encoder::new();
my_struct.encode(&mut e).unwrap();

assert_eq!(e.toml.get(&"foo".to_string()), Some(&Value::Integer(4)))

Fields§

§toml: Table

Output TOML that is emitted. The current version of this encoder forces the top-level representation of a structure to be a table.

This field can be used to extract the return value after feeding a value into this Encoder.

Implementations§

source§

impl Encoder

source

pub fn new() -> Encoder

Constructs a new encoder which will emit to the given output stream.

Trait Implementations§

source§

impl Encoder for Encoder

§

type Error = Error

The error type for method results.
source§

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

Emit a nil value. Read more
source§

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

Emit a usize value.
source§

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

Emit a u8 value.
source§

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

Emit a u16 value.
source§

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

Emit a u32 value.
source§

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

Emit a u64 value.
source§

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

Emit a isize value.
source§

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

Emit a i8 value.
source§

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

Emit a i16 value.
source§

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

Emit a i32 value.
source§

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

Emit a i64 value.
source§

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

Emit a bool value. Read more
source§

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

Emit a f32 value.
source§

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

Emit a f64 value.
source§

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

Emit a char value. Read more
source§

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

Emit a string value.
source§

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

Emit an enumeration value. Read more
source§

fn emit_enum_variant<F>( &mut self, _v_name: &str, _v_id: usize, _len: usize, f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error>,

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

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

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

fn emit_enum_struct_variant<F>( &mut self, _v_name: &str, _v_id: usize, _len: usize, _f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> Result<(), Error>,

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

fn emit_enum_struct_variant_field<F>( &mut self, _f_name: &str, _f_idx: usize, _f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> 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 Encoder) -> Result<(), Error>,

Emit a struct value. Read more
source§

fn emit_struct_field<F>( &mut self, f_name: &str, _f_idx: usize, f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> 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 Encoder) -> 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 Encoder) -> 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 Encoder) -> Result<(), Error>,

Emit a tuple struct value. Read more
source§

fn emit_tuple_struct_arg<F>( &mut self, _f_idx: usize, _f: F, ) -> Result<(), Error>
where F: FnOnce(&mut Encoder) -> 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 Encoder) -> 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 Encoder) -> 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 Encoder) -> 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 Encoder) -> 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 Encoder) -> 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 Encoder) -> 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 Encoder) -> Result<(), Error>,

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

Auto Trait Implementations§

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

§

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.