about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSylvainDe <sylvain.desodt+github@gmail.com>2022-05-19 21:58:39 +0200
committerSylvainDe <sylvain.desodt+github@gmail.com>2022-05-19 22:01:43 +0200
commit4c1daba940837de49c1a45ce93356c87de27d433 (patch)
tree1b380ac04d46f988c482e1c48632f84290baa718
parentc0672870491e84362f76ddecd50fa229f9b06dff (diff)
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.
-rw-r--r--library/core/src/str/traits.rs8
1 files 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<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 {