[go: up one dir, main page]

ToToml

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§