Trait tomlconv::FromToml [] [src]

pub trait FromToml: for<'a> Deserialize<'a> {
    fn from_toml_file<P: AsRef<Path>>(path: P) -> Result<Self> { ... }
    fn from_toml_reader<R: Read>(reader: R) -> Result<Self> { ... }
    fn from_toml_str(toml: &str) -> Result<Self> { ... }
    fn from_toml(toml: Value) -> Result<Self> { ... }
}

This trait allows to convert TOML objects to deserializable values.

Examples

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

use tomlconv::FromToml;

// Defines a deserializable struct.
#[derive(Deserialize)]
struct Foo {
    bar: String,
    baz: usize
}
impl FromToml for Foo {}

// Converts from the TOML string to a `Foo` value.
let toml = r#"
bar = "aaa"
baz = 123
"#;
let foo = Foo::from_toml_str(toml).unwrap();
assert_eq!(foo.bar, "aaa");
assert_eq!(foo.baz, 123);

Provided Methods

Converts from the TOML file to an instance of this implementation.

Reads a TOML string from the reader and converts it to an instance of this implementation.

Converts from the TOML string to an instance of this implementation.

Converts from the TOML value to an instance of this implementation.

Implementors