add example for from_str
This commit is contained in:
parent
6bf46cae38
commit
0d3b3e3a36
31
src/de.rs
31
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
|
/// This function will attempt to interpret `s` as a TOML document and
|
||||||
/// deserialize `T` from the document.
|
/// 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>
|
pub fn from_str<'de, T>(s: &'de str) -> Result<T, Error>
|
||||||
where T: de::Deserialize<'de>,
|
where T: de::Deserialize<'de>,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue