Skip to content

Commit

Permalink
Consistently apply Example and Errors headings
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 7, 2018
1 parent e9570bf commit 49e544e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
58 changes: 32 additions & 26 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2121,15 +2121,7 @@ where

/// Deserialize an instance of type `T` from an IO stream of JSON.
///
/// # Errors
///
/// This conversion can fail if the structure of the input does not match the
/// structure expected by `T`, for example if `T` is a struct type but the input
/// contains something other than a JSON map. It can also fail if the structure
/// is correct but `T`'s implementation of `Deserialize` decides that something
/// is wrong with the data, for example required struct fields are missing from
/// the JSON map or some number is too big to fit in the expected primitive
/// type.
/// # Example
///
/// ```rust
/// #[macro_use]
Expand Down Expand Up @@ -2166,15 +2158,6 @@ where
/// println!("{:#?}", u);
/// }
/// ```
pub fn from_reader<R, T>(rdr: R) -> Result<T>
where
R: io::Read,
T: de::DeserializeOwned,
{
from_trait(read::IoRead::new(rdr))
}

/// Deserialize an instance of type `T` from bytes of JSON text.
///
/// # Errors
///
Expand All @@ -2185,6 +2168,17 @@ where
/// is wrong with the data, for example required struct fields are missing from
/// the JSON map or some number is too big to fit in the expected primitive
/// type.
pub fn from_reader<R, T>(rdr: R) -> Result<T>
where
R: io::Read,
T: de::DeserializeOwned,
{
from_trait(read::IoRead::new(rdr))
}

/// Deserialize an instance of type `T` from bytes of JSON text.
///
/// # Example
///
/// ```rust
/// #[macro_use]
Expand All @@ -2210,14 +2204,6 @@ where
/// println!("{:#?}", u);
/// }
/// ```
pub fn from_slice<'a, T>(v: &'a [u8]) -> Result<T>
where
T: de::Deserialize<'a>,
{
from_trait(read::SliceRead::new(v))
}

/// Deserialize an instance of type `T` from a string of JSON text.
///
/// # Errors
///
Expand All @@ -2228,6 +2214,16 @@ where
/// is wrong with the data, for example required struct fields are missing from
/// the JSON map or some number is too big to fit in the expected primitive
/// type.
pub fn from_slice<'a, T>(v: &'a [u8]) -> Result<T>
where
T: de::Deserialize<'a>,
{
from_trait(read::SliceRead::new(v))
}

/// Deserialize an instance of type `T` from a string of JSON text.
///
/// # Example
///
/// ```rust
/// #[macro_use]
Expand All @@ -2253,6 +2249,16 @@ where
/// println!("{:#?}", u);
/// }
/// ```
///
/// # Errors
///
/// This conversion can fail if the structure of the input does not match the
/// structure expected by `T`, for example if `T` is a struct type but the input
/// contains something other than a JSON map. It can also fail if the structure
/// is correct but `T`'s implementation of `Deserialize` decides that something
/// is wrong with the data, for example required struct fields are missing from
/// the JSON map or some number is too big to fit in the expected primitive
/// type.
pub fn from_str<'a, T>(s: &'a str) -> Result<T>
where
T: de::Deserialize<'a>,
Expand Down
20 changes: 13 additions & 7 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ mod ser;
/// Convert a `T` into `serde_json::Value` which is an enum that can represent
/// any valid JSON data.
///
/// # Example
///
/// ```rust
/// extern crate serde;
///
Expand Down Expand Up @@ -1087,13 +1089,7 @@ where

/// Interpret a `serde_json::Value` as an instance of type `T`.
///
/// This conversion can fail if the structure of the Value does not match the
/// structure expected by `T`, for example if `T` is a struct type but the Value
/// contains something other than a JSON map. It can also fail if the structure
/// is correct but `T`'s implementation of `Deserialize` decides that something
/// is wrong with the data, for example required struct fields are missing from
/// the JSON map or some number is too big to fit in the expected primitive
/// type.
/// # Example
///
/// ```rust
/// #[macro_use]
Expand Down Expand Up @@ -1121,6 +1117,16 @@ where
/// println!("{:#?}", u);
/// }
/// ```
///
/// # Errors
///
/// This conversion can fail if the structure of the Value does not match the
/// structure expected by `T`, for example if `T` is a struct type but the Value
/// contains something other than a JSON map. It can also fail if the structure
/// is correct but `T`'s implementation of `Deserialize` decides that something
/// is wrong with the data, for example required struct fields are missing from
/// the JSON map or some number is too big to fit in the expected primitive
/// type.
pub fn from_value<T>(value: Value) -> Result<T, Error>
where
T: DeserializeOwned,
Expand Down

0 comments on commit 49e544e

Please sign in to comment.