diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2025-02-07 15:31:55 +0100 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2025-06-03 15:41:47 -0700 |
| commit | f412d05e50d0a682502e225b41db77bf4aa302e2 (patch) | |
| tree | 4e33c53319ee15ae01d14ed77d62ad0911f46353 | |
| parent | 252ad18415723a7485b0e2950f1b641109c9d4ef (diff) | |
| download | rust-f412d05e50d0a682502e225b41db77bf4aa302e2.tar.gz rust-f412d05e50d0a682502e225b41db77bf4aa302e2.zip | |
Add some more description of interactions between `Display` and `FromStr`
| -rw-r--r-- | library/core/src/str/traits.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index 85d5fa1ef92..2f425c82dc8 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -765,6 +765,12 @@ unsafe impl SliceIndex<str> for ops::RangeToInclusive<usize> { /// mistake, unless the type has provided and documented additional guarantees about its `Display` /// and `FromStr` implementations. /// +/// If a type happens to have a lossless `Display` implementation whose output is meant to be +/// conveniently machine-parseable and not just meant for human consumption, then the type may wish +/// to accept the same format in `FromStr`, and document that usage. Having both `Display` and +/// `FromStr` implementations where the result of `Display` cannot be parsed with `FromStr` may +/// surprise users. (However, the result of such parsing may not have the same value as the input.) +/// /// # Examples /// /// Basic implementation of `FromStr` on an example `Point` type: |
