Function toml::from_str

source ·
pub fn from_str<T>(s: &str) -> Result<T, Error>
Available on crate feature parse only.
Expand description

Deserializes a string into a type.

This function will attempt to interpret s as a TOML document and deserialize T from the document.

To deserializes TOML values, instead of documents, see ValueDeserializer.


use serde::Deserialize;

struct Config {
    title: String,
    owner: Owner,

struct Owner {
    name: String,

let config: Config = toml::from_str(r#"
    title = 'TOML Example'

    name = 'Lisa'

assert_eq!(config.title, "TOML Example");
assert_eq!(, "Lisa");