str: fix comments for FromStr for bool
Fix the return type in the comments.
An old commit 082bfde412
("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 <laijs@cn.fujitsu.com>
This commit is contained in:
parent
b4c965ee80
commit
bc98e9fbc2
1 changed files with 13 additions and 2 deletions
|
@ -134,12 +134,23 @@ impl FromStr for bool {
|
||||||
|
|
||||||
/// Parse a `bool` from a string.
|
/// Parse a `bool` from a string.
|
||||||
///
|
///
|
||||||
/// Yields an `Option<bool>`, because `s` may or may not actually be
|
/// Yields a `Result<bool, ParseBoolError>`, because `s` may or may not
|
||||||
/// parseable.
|
/// actually be parseable.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// use std::str::FromStr;
|
||||||
|
///
|
||||||
|
/// assert_eq!(FromStr::from_str("true"), Ok(true));
|
||||||
|
/// assert_eq!(FromStr::from_str("false"), Ok(false));
|
||||||
|
/// assert!(<bool as FromStr>::from_str("not even a boolean").is_err());
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Note, in many cases, the StrExt::parse() which is based on
|
||||||
|
/// this FromStr::from_str() is more proper.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
/// assert_eq!("true".parse(), Ok(true));
|
/// assert_eq!("true".parse(), Ok(true));
|
||||||
/// assert_eq!("false".parse(), Ok(false));
|
/// assert_eq!("false".parse(), Ok(false));
|
||||||
/// assert!("not even a boolean".parse::<bool>().is_err());
|
/// assert!("not even a boolean".parse::<bool>().is_err());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue