Skip to content

Commit 49e544e

Browse files
committed
Consistently apply Example and Errors headings
1 parent e9570bf commit 49e544e

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

src/de.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,15 +2121,7 @@ where
21212121

21222122
/// Deserialize an instance of type `T` from an IO stream of JSON.
21232123
///
2124-
/// # Errors
2125-
///
2126-
/// This conversion can fail if the structure of the input does not match the
2127-
/// structure expected by `T`, for example if `T` is a struct type but the input
2128-
/// contains something other than a JSON map. It can also fail if the structure
2129-
/// is correct but `T`'s implementation of `Deserialize` decides that something
2130-
/// is wrong with the data, for example required struct fields are missing from
2131-
/// the JSON map or some number is too big to fit in the expected primitive
2132-
/// type.
2124+
/// # Example
21332125
///
21342126
/// ```rust
21352127
/// #[macro_use]
@@ -2166,15 +2158,6 @@ where
21662158
/// println!("{:#?}", u);
21672159
/// }
21682160
/// ```
2169-
pub fn from_reader<R, T>(rdr: R) -> Result<T>
2170-
where
2171-
R: io::Read,
2172-
T: de::DeserializeOwned,
2173-
{
2174-
from_trait(read::IoRead::new(rdr))
2175-
}
2176-
2177-
/// Deserialize an instance of type `T` from bytes of JSON text.
21782161
///
21792162
/// # Errors
21802163
///
@@ -2185,6 +2168,17 @@ where
21852168
/// is wrong with the data, for example required struct fields are missing from
21862169
/// the JSON map or some number is too big to fit in the expected primitive
21872170
/// type.
2171+
pub fn from_reader<R, T>(rdr: R) -> Result<T>
2172+
where
2173+
R: io::Read,
2174+
T: de::DeserializeOwned,
2175+
{
2176+
from_trait(read::IoRead::new(rdr))
2177+
}
2178+
2179+
/// Deserialize an instance of type `T` from bytes of JSON text.
2180+
///
2181+
/// # Example
21882182
///
21892183
/// ```rust
21902184
/// #[macro_use]
@@ -2210,14 +2204,6 @@ where
22102204
/// println!("{:#?}", u);
22112205
/// }
22122206
/// ```
2213-
pub fn from_slice<'a, T>(v: &'a [u8]) -> Result<T>
2214-
where
2215-
T: de::Deserialize<'a>,
2216-
{
2217-
from_trait(read::SliceRead::new(v))
2218-
}
2219-
2220-
/// Deserialize an instance of type `T` from a string of JSON text.
22212207
///
22222208
/// # Errors
22232209
///
@@ -2228,6 +2214,16 @@ where
22282214
/// is wrong with the data, for example required struct fields are missing from
22292215
/// the JSON map or some number is too big to fit in the expected primitive
22302216
/// type.
2217+
pub fn from_slice<'a, T>(v: &'a [u8]) -> Result<T>
2218+
where
2219+
T: de::Deserialize<'a>,
2220+
{
2221+
from_trait(read::SliceRead::new(v))
2222+
}
2223+
2224+
/// Deserialize an instance of type `T` from a string of JSON text.
2225+
///
2226+
/// # Example
22312227
///
22322228
/// ```rust
22332229
/// #[macro_use]
@@ -2253,6 +2249,16 @@ where
22532249
/// println!("{:#?}", u);
22542250
/// }
22552251
/// ```
2252+
///
2253+
/// # Errors
2254+
///
2255+
/// This conversion can fail if the structure of the input does not match the
2256+
/// structure expected by `T`, for example if `T` is a struct type but the input
2257+
/// contains something other than a JSON map. It can also fail if the structure
2258+
/// is correct but `T`'s implementation of `Deserialize` decides that something
2259+
/// is wrong with the data, for example required struct fields are missing from
2260+
/// the JSON map or some number is too big to fit in the expected primitive
2261+
/// type.
22562262
pub fn from_str<'a, T>(s: &'a str) -> Result<T>
22572263
where
22582264
T: de::Deserialize<'a>,

src/value/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ mod ser;
10181018
/// Convert a `T` into `serde_json::Value` which is an enum that can represent
10191019
/// any valid JSON data.
10201020
///
1021+
/// # Example
1022+
///
10211023
/// ```rust
10221024
/// extern crate serde;
10231025
///
@@ -1087,13 +1089,7 @@ where
10871089

10881090
/// Interpret a `serde_json::Value` as an instance of type `T`.
10891091
///
1090-
/// This conversion can fail if the structure of the Value does not match the
1091-
/// structure expected by `T`, for example if `T` is a struct type but the Value
1092-
/// contains something other than a JSON map. It can also fail if the structure
1093-
/// is correct but `T`'s implementation of `Deserialize` decides that something
1094-
/// is wrong with the data, for example required struct fields are missing from
1095-
/// the JSON map or some number is too big to fit in the expected primitive
1096-
/// type.
1092+
/// # Example
10971093
///
10981094
/// ```rust
10991095
/// #[macro_use]
@@ -1121,6 +1117,16 @@ where
11211117
/// println!("{:#?}", u);
11221118
/// }
11231119
/// ```
1120+
///
1121+
/// # Errors
1122+
///
1123+
/// This conversion can fail if the structure of the Value does not match the
1124+
/// structure expected by `T`, for example if `T` is a struct type but the Value
1125+
/// contains something other than a JSON map. It can also fail if the structure
1126+
/// is correct but `T`'s implementation of `Deserialize` decides that something
1127+
/// is wrong with the data, for example required struct fields are missing from
1128+
/// the JSON map or some number is too big to fit in the expected primitive
1129+
/// type.
11241130
pub fn from_value<T>(value: Value) -> Result<T, Error>
11251131
where
11261132
T: DeserializeOwned,

0 commit comments

Comments
 (0)