Skip to content

Commit 4c1daba

Browse files
committed
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.
1 parent c067287 commit 4c1daba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/core/src/str/traits.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,12 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
530530
/// }
531531
/// }
532532
///
533-
/// let p = Point::from_str("(1,2)");
534-
/// assert_eq!(p.unwrap(), Point{ x: 1, y: 2} )
533+
/// let expected = Ok(Point { x: 1, y: 2 });
534+
/// // Explicit call
535+
/// assert_eq!(Point::from_str("(1,2)"), expected);
536+
/// // Implicit calls, through parse
537+
/// assert_eq!("(1,2)".parse(), expected);
538+
/// assert_eq!("(1,2)".parse::<Point>(), expected);
535539
/// ```
536540
#[stable(feature = "rust1", since = "1.0.0")]
537541
pub trait FromStr: Sized {

0 commit comments

Comments
 (0)