Skip to content

Commit 7ba5d26

Browse files
committed
FromStr: Rework explanation of FromStr/Display round-tripping
- Drop the phrasing "usually a mistake". - Mention that `Display` may not be lossless. - Drop a misplaced parenthetical about round-tripping that didn't fit the paragraph it was in.
1 parent f412d05 commit 7ba5d26

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

library/core/src/str/traits.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,20 +756,19 @@ unsafe impl SliceIndex<str> for ops::RangeToInclusive<usize> {
756756
/// parse an `i32` with `FromStr`, but not a `&i32`. You can parse a struct that
757757
/// contains an `i32`, but not one that contains an `&i32`.
758758
///
759-
/// # Input format
759+
/// # Input format and round-tripping
760760
///
761761
/// The input format expected by a type's `FromStr` implementation depends on the type. Check the
762762
/// type's documentation for the input formats it knows how to parse. Note that the input format of
763763
/// a type's `FromStr` implementation might not necessarily accept the output format of its
764-
/// `Display` implementation; thus, calling `.parse()` on the output from `Display` is usually a
765-
/// mistake, unless the type has provided and documented additional guarantees about its `Display`
766-
/// and `FromStr` implementations.
764+
/// `Display` implementation, and even if it does, the `Display` implementation may not be lossless
765+
/// so the round-trip may lose information.
767766
///
768-
/// If a type happens to have a lossless `Display` implementation whose output is meant to be
767+
/// However, if a type has a lossless `Display` implementation whose output is meant to be
769768
/// conveniently machine-parseable and not just meant for human consumption, then the type may wish
770769
/// to accept the same format in `FromStr`, and document that usage. Having both `Display` and
771770
/// `FromStr` implementations where the result of `Display` cannot be parsed with `FromStr` may
772-
/// surprise users. (However, the result of such parsing may not have the same value as the input.)
771+
/// surprise users.
773772
///
774773
/// # Examples
775774
///

0 commit comments

Comments
 (0)