Struct toml::Encoder [] [src]

pub struct Encoder {
    pub toml: Table,
    // some fields omitted
}

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.

Methods

impl Encoder
[src]

fn new() -> Encoder

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

Trait Implementations

impl Encoder for Encoder
[src]

type Error = Error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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>

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

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>

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>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl Serializer for Encoder
[src]

type Error = Error

The error type that can be returned if some error occurs during serialization.

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

Serializes a bool value.

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

Serializes a i64 value.

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

Serializes au64` value.

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

Serializes a f64 value.

fn serialize_str(&mut self, value: &str) -> Result<()Error>

Serializes a &str.

fn serialize_unit(&mut self) -> Result<()Error>

Serializes a () value.

fn serialize_none(&mut self) -> Result<()Error>

Serializes a None value..serialize

fn serialize_some<V>(&mut self, value: V) -> Result<()Error> where V: Serialize

Serializes a Some(...) value.

fn serialize_seq<V>(&mut self, visitor: V) -> Result<()Error> where V: SeqVisitor

Serializes a sequence. Read more

fn serialize_seq_elt<T>(&mut self, value: T) -> Result<()Error> where T: Serialize

Serializes a sequence element.

fn serialize_map<V>(&mut self, visitor: V) -> Result<()Error> where V: MapVisitor

Serializes a map. Read more

fn serialize_map_elt<K, V>(&mut self, key: K, value: V) -> Result<()Error> where K: Serialize, V: Serialize

Serializes a map element (key-value pair).

fn serialize_newtype_struct<T>(&mut self, _name: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize

Allows a tuple struct with a single element, also known as a newtyped value, to be more efficiently serialized than a tuple struct with multiple items. By default it just serializes the value as a tuple struct sequence. Read more

fn serialize_newtype_variant<T>(&mut self, _name: &'static str, _variant_index: usize, _variant: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize

Allows a variant with a single item to be more efficiently serialized than a variant with multiple items. By default it just serializes the value as a tuple variant sequence. Read more

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

Serializes a isize value. By default it casts the value to a i64 and passes it to the serialize_i64 method. Read more

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

Serializes a i8 value. By default it casts the value to a i64 and passes it to the serialize_i64 method. Read more

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

Serializes a i16 value. By default it casts the value to a i64 and passes it to the serialize_i64 method. Read more

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

Serializes a i32 value. By default it casts the value to a i64 and passes it to the serialize_i64 method. Read more

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

Serializes a usize value. By default it casts the value to a u64 and passes it to the serialize_u64 method. Read more

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

Serializes a u8 value. By default it casts the value to a u64 and passes it to the serialize_u64 method. Read more

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

Serializes a u32 value. By default it casts the value to a u64 and passes it to the serialize_u64 method. Read more

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

Serializes a u32 value. By default it casts the value to a u64 and passes it to the serialize_u64 method. Read more

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

Serializes a f32 value. By default it casts the value to a f64 and passes it to the serialize_f64 method. Read more

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

Serializes a character. By default it serializes it as a &str containing a single character. Read more

fn serialize_bytes(&mut self, value: &[u8]) -> Result<(), Self::Error>

Enables those serialization formats that support serializing byte slices separately from generic arrays. By default it serializes as a regular array. Read more

fn serialize_unit_struct(&mut self, _name: &'static str) -> Result<(), Self::Error>

Serializes a unit struct value. Read more

fn serialize_unit_variant(&mut self, _name: &'static str, _variant_index: usize, _variant: &'static str) -> Result<(), Self::Error>

Serializes a unit variant, otherwise known as a variant with no arguments. Read more

fn serialize_tuple<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor

Serializes a tuple. Read more

fn serialize_tuple_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize

Serializes a tuple element. Read more

fn serialize_fixed_size_array<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor

Serializes a fixed-size array. Read more

fn serialize_tuple_struct<V>(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor

Serializes a tuple struct. Read more

fn serialize_tuple_struct_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize

Serializes a tuple struct element. Read more

fn serialize_tuple_variant<V>(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor

Serializes a tuple variant. Read more

fn serialize_tuple_variant_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize

Serializes a tuple element. Read more

fn serialize_struct<V>(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor

Serializes a struct. Read more

fn serialize_struct_elt<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize

Serializes an element of a struct. Read more

fn serialize_struct_variant<V>(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor

Serializes a struct variant. Read more

fn serialize_struct_variant_elt<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize

Serializes an element of a struct variant. Read more