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§
sourcefn to_toml_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
fn to_toml_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Converts this to a TOML string and writes it to the speficied file.
sourcefn to_toml_writer<W: Write>(&self, writer: W) -> Result<()>
fn to_toml_writer<W: Write>(&self, writer: W) -> Result<()>
Converts this to a TOML string and writes it to the writer.
sourcefn to_toml_string(&self) -> Result<String>
fn to_toml_string(&self) -> Result<String>
Converts this to a TOML string.