From 4c1daba940837de49c1a45ce93356c87de27d433 Mon Sep 17 00:00:00 2001 From: SylvainDe Date: Thu, 19 May 2022 21:58:39 +0200 Subject: [PATCH] Add implicit call to from_str via parse in documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- library/core/src/str/traits.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index 8b6b4fa02f8..32c31803a51 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -530,8 +530,12 @@ unsafe impl const SliceIndex for ops::RangeToInclusive { /// } /// } /// -/// 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::(), expected); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait FromStr: Sized {