diff options
author | Raphaƫl Huchet <rap2hpoutre@users.noreply.github.com> | 2017-05-10 16:49:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-10 16:49:35 +0200 |
commit | d8829a1268ac04277f0760b1820388b334d0bf21 (patch) | |
tree | fd3df959fe268239e131000561beb4e4ba9de491 | |
parent | f94dc8d69b22f330e6be19882f2f02e09895f18f (diff) | |
download | milf-rs-d8829a1268ac04277f0760b1820388b334d0bf21.tar.gz milf-rs-d8829a1268ac04277f0760b1820388b334d0bf21.zip |
add example for from_str
-rw-r--r-- | src/de.rs | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -33,6 +33,37 @@ pub fn from_slice<'de, T>(bytes: &'de [u8]) -> Result<T, Error> /// /// This function will attempt to interpret `s` as a TOML document and /// deserialize `T` from the document. +/// +/// # Examples +/// +/// ```no_run +/// #[macro_use] +/// extern crate serde_derive; +/// extern crate toml; +/// +/// #[derive(Deserialize)] +/// struct Config { +/// title: String, +/// owner: Owner, +/// } +/// +/// #[derive(Deserialize)] +/// struct Owner { +/// name: String, +/// } +/// +/// fn main() { +/// let config: Config = toml::from_str(r#" +/// title = 'TOML Example' +/// +/// [owner] +/// name = 'Lisa' +/// "#).unwrap(); +/// +/// assert_eq!(config.title, "TOML Example"); +/// assert_eq!(config.owner.name, "Lisa"); +/// } +/// ``` pub fn from_str<'de, T>(s: &'de str) -> Result<T, Error> where T: de::Deserialize<'de>, { |