Trait serdeconv::ToToml

source ·
pub trait ToToml: Serialize {
    // Provided methods
    fn to_toml_file<P: AsRef<Path>>(&self, path: P) -> Result<()> { ... }
    fn to_toml_writer<W: Write>(&self, writer: W) -> Result<()> { ... }
    fn to_toml_string(&self) -> Result<String> { ... }
}
Expand description

This trait allows to convert serializable values to TOML objects.

Examples

extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serdeconv;

use serdeconv::ToToml;

// Defines a serializable struct.
#[derive(Serialize)]
struct Foo {
    bar: &'static str,
    baz: usize
}
impl ToToml for Foo {}

// Converts the `Foo` value to a TOML string.
let foo = Foo { bar: "aaa", baz: 123 };
let toml = foo.to_toml_string().unwrap();
assert_eq!(toml, "\
bar = \"aaa\"
baz = 123
");

Provided Methods§

source

fn to_toml_file<P: AsRef<Path>>(&self, path: P) -> Result<()>

Converts this to a TOML string and writes it to the speficied file.

source

fn to_toml_writer<W: Write>(&self, writer: W) -> Result<()>

Converts this to a TOML string and writes it to the writer.

source

fn to_toml_string(&self) -> Result<String>

Converts this to a TOML string.

Implementors§