about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2022-05-21 11:39:48 +0200
committerGitHub <noreply@github.com>2022-05-21 11:39:48 +0200
commit1210b50dbb37b24178bfdf8494daa2bddcaf1c68 (patch)
tree34b8b3f4f754d75abcf10b2c1199f44f85d7f352
parent4f372b14dea58cbff1dd76bb651f9c035d3f6e7b (diff)
parent4c1daba940837de49c1a45ce93356c87de27d433 (diff)
downloadrust-1210b50dbb37b24178bfdf8494daa2bddcaf1c68.tar.gz
rust-1210b50dbb37b24178bfdf8494daa2bddcaf1c68.zip
Rollup merge of #97190 - SylvainDe:master, r=Dylan-DPC
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 {