aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-05-10 13:19:47 -0500
committerGitHub <noreply@github.com>2017-05-10 13:19:47 -0500
commit998eec3e00163df3c85c634c31aa5e88fdbcc0b4 (patch)
treea640fccd028324810a4be70096db967de3234b72
parent1000f0b6292a10ca853f297f0ecb531c27779c11 (diff)
parent89dd454ef28d3a885e1e6420aa8e67e1fd3466e5 (diff)
downloadmilf-rs-998eec3e00163df3c85c634c31aa5e88fdbcc0b4.tar.gz
milf-rs-998eec3e00163df3c85c634c31aa5e88fdbcc0b4.zip
Merge pull request #172 from rap2hpoutre/patch-1
add example for from_str
-rw-r--r--src/de.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/de.rs b/src/de.rs
index bd73649..bd4ead0 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -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
+///
+/// ```
+/// #[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>,
{