We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d695a49 commit c1c1abcCopy full SHA for c1c1abc
library/core/src/str/traits.rs
@@ -519,12 +519,14 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
519
/// type Err = ParseIntError;
520
///
521
/// fn from_str(s: &str) -> Result<Self, Self::Err> {
522
-/// let coords: Vec<&str> = s.trim_matches(|p| p == '(' || p == ')' )
523
-/// .split(',')
524
-/// .collect();
525
-///
526
-/// let x_fromstr = coords[0].parse::<i32>()?;
527
-/// let y_fromstr = coords[1].parse::<i32>()?;
+/// let (x, y) = s
+/// .strip_prefix('(')
+/// .and_then(|s| s.strip_suffix(')'))
+/// .and_then(|s| s.split_once(','))
+/// .unwrap();
+///
528
+/// let x_fromstr = x.parse::<i32>()?;
529
+/// let y_fromstr = y.parse::<i32>()?;
530
531
/// Ok(Point { x: x_fromstr, y: y_fromstr })
532
/// }
0 commit comments