Skip to content

Commit ea208a8

Browse files
committed
Rollup merge of #22989 - laijs:fix_FromStr_bool_comment, r=alexcrichton
Fix the return type in the comments. An old commit 082bfde (\"Fallout of std::str stabilization\") removed the example of FromStr::from_str(), this commit adds it back. But the example of StrExt::parse() is still kept with an additinal note. Signed-off-by: Lai Jiangshan <[email protected]>
2 parents 873d312 + bc98e9f commit ea208a8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/libcore/str/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,23 @@ impl FromStr for bool {
134134

135135
/// Parse a `bool` from a string.
136136
///
137-
/// Yields an `Option<bool>`, because `s` may or may not actually be
138-
/// parseable.
137+
/// Yields a `Result<bool, ParseBoolError>`, because `s` may or may not
138+
/// actually be parseable.
139139
///
140140
/// # Examples
141141
///
142142
/// ```rust
143+
/// use std::str::FromStr;
144+
///
145+
/// assert_eq!(FromStr::from_str("true"), Ok(true));
146+
/// assert_eq!(FromStr::from_str("false"), Ok(false));
147+
/// assert!(<bool as FromStr>::from_str("not even a boolean").is_err());
148+
/// ```
149+
///
150+
/// Note, in many cases, the StrExt::parse() which is based on
151+
/// this FromStr::from_str() is more proper.
152+
///
153+
/// ```rust
143154
/// assert_eq!("true".parse(), Ok(true));
144155
/// assert_eq!("false".parse(), Ok(false));
145156
/// assert!("not even a boolean".parse::<bool>().is_err());

0 commit comments

Comments
 (0)