Skip to content

Commit 4dbd256

Browse files
committed
Explain use of display adapters
1 parent 37b6533 commit 4dbd256

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/core/src/fmt/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,23 @@ pub use macros::Debug;
633633
/// [tostring]: ../../std/string/trait.ToString.html
634634
/// [tostring_function]: ../../std/string/trait.ToString.html#tymethod.to_string
635635
///
636+
/// # Internationalization
637+
///
638+
/// Because a type only has one `Display` implementation, it is often preferable
639+
/// to only implement `Display` when there is a single most "obvious" way that
640+
/// values can be formatted as text. This could mean formatting according to the
641+
/// "invariant" culture and "undefined" locale, or it could mean that the type
642+
/// display is designed for a specific culture/locale, such as developer logs.
643+
///
644+
/// If not all values have a justifiably canonical textual format or if you want
645+
/// to support alternative formats not covered by the standard set of possible
646+
/// [formatting traits], the most flexible approach is display adapters: methods
647+
/// like [`str::escape_default`] or [`Path::display`] which create a wrapper
648+
/// implementing `Display` to output the specific display format.
649+
///
650+
/// [formatting traits]: ../../std/fmt/index.html#formatting-traits
651+
/// [`Path::display`]: ../../std/path/struct.Path.html#method.display
652+
///
636653
/// # Examples
637654
///
638655
/// Implementing `Display` on a type:

0 commit comments

Comments
 (0)