Skip to content

Commit dcfb1ec

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 5745e1b commit dcfb1ec

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
@@ -937,8 +937,13 @@ pub use macros::Debug;
937937
/// It may omit internal state, precision, or other information the type does not consider important
938938
/// for user-facing output, as determined by the type. As such, the output of `Display` might not be
939939
/// possible to parse, and even if it is, the result of parsing might not exactly match the original
940-
/// value. Calling `.parse()` on the output from `Display` is usually a mistake, unless the type has
941-
/// provided and documented additional guarantees about its `Display` and `FromStr` implementations.
940+
/// value.
941+
///
942+
/// However, if a type has a lossless `Display` implementation whose output is meant to be
943+
/// conveniently machine-parseable and not just meant for human consumption, then the type may wish
944+
/// to accept the same format in `FromStr`, and document that usage. Having both `Display` and
945+
/// `FromStr` implementations where the result of `Display` cannot be parsed with `FromStr` may
946+
/// surprise users.
942947
///
943948
/// # Internationalization
944949
///

0 commit comments

Comments
 (0)