Skip to content

Commit

Permalink
Rollup merge of #97190 - SylvainDe:master, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Add implicit call to from_str via parse in documentation

The documentation mentions "FromStr’s from_str method is often used implicitly,
through str’s parse method. See parse’s documentation for examples.".

It may be nicer to show that in the code example as well.
  • Loading branch information
GuillaumeGomez authored May 21, 2022
2 parents 4f372b1 + 4c1daba commit 1210b50
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,12 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
/// }
/// }
///
/// let p = Point::from_str("(1,2)");
/// assert_eq!(p.unwrap(), Point{ x: 1, y: 2} )
/// let expected = Ok(Point { x: 1, y: 2 });
/// // Explicit call
/// assert_eq!(Point::from_str("(1,2)"), expected);
/// // Implicit calls, through parse
/// assert_eq!("(1,2)".parse(), expected);
/// assert_eq!("(1,2)".parse::<Point>(), expected);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub trait FromStr: Sized {
Expand Down

0 comments on commit 1210b50

Please sign in to comment.