Skip to content

Commit 742014e

Browse files
committed
Display: Rework explanation of FromStr/Display round-tripping
- Drop "usually a mistake" - Add phrasing from `FromStr` about round-tripping, and about how the inability to round-trip may surprise users.
1 parent 7ba5d26 commit 742014e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/core/src/fmt/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,13 @@ pub use macros::Debug;
934934
/// It may omit internal state, precision, or other information the type does not consider important
935935
/// for user-facing output, as determined by the type. As such, the output of `Display` might not be
936936
/// possible to parse, and even if it is, the result of parsing might not exactly match the original
937-
/// value. Calling `.parse()` on the output from `Display` is usually a mistake, unless the type has
938-
/// provided and documented additional guarantees about its `Display` and `FromStr` implementations.
937+
/// value.
938+
///
939+
/// However, if a type has a lossless `Display` implementation whose output is meant to be
940+
/// conveniently machine-parseable and not just meant for human consumption, then the type may wish
941+
/// to accept the same format in `FromStr`, and document that usage. Having both `Display` and
942+
/// `FromStr` implementations where the result of `Display` cannot be parsed with `FromStr` may
943+
/// surprise users.
939944
///
940945
/// # Internationalization
941946
///

0 commit comments

Comments
 (0)