From 0d3b3e3a363d32b1c9a5b50b537373ab53962673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Huchet?= Date: Wed, 10 May 2017 16:49:35 +0200 Subject: [PATCH 1/2] add example for from_str --- src/de.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/de.rs b/src/de.rs index bd73649..de916c8 100644 --- a/src/de.rs +++ b/src/de.rs @@ -33,6 +33,37 @@ pub fn from_slice<'de, T>(bytes: &'de [u8]) -> Result /// /// 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 where T: de::Deserialize<'de>, { From 9158482ed907eeb982eae5b2e9e478739026f763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Huchet?= Date: Wed, 10 May 2017 17:17:58 +0200 Subject: [PATCH 2/2] Update de.rs --- src/de.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de.rs b/src/de.rs index de916c8..bd4ead0 100644 --- a/src/de.rs +++ b/src/de.rs @@ -36,7 +36,7 @@ pub fn from_slice<'de, T>(bytes: &'de [u8]) -> Result /// /// # Examples /// -/// ```no_run +/// ``` /// #[macro_use] /// extern crate serde_derive; /// extern crate toml;