Skip to content

Commit f412d05

Browse files
committed
Add some more description of interactions between Display and FromStr
1 parent 252ad18 commit f412d05

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/core/src/str/traits.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,12 @@ unsafe impl SliceIndex<str> for ops::RangeToInclusive<usize> {
765765
/// mistake, unless the type has provided and documented additional guarantees about its `Display`
766766
/// and `FromStr` implementations.
767767
///
768+
/// If a type happens to have a lossless `Display` implementation whose output is meant to be
769+
/// conveniently machine-parseable and not just meant for human consumption, then the type may wish
770+
/// to accept the same format in `FromStr`, and document that usage. Having both `Display` and
771+
/// `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.)
773+
///
768774
/// # Examples
769775
///
770776
/// Basic implementation of `FromStr` on an example `Point` type:

0 commit comments

Comments
 (0)