Skip to content

Commit afff64e

Browse files
committed
document format_args! further wrt. Debug & Display"
1 parent 5201e7c commit afff64e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/macros.rs

+12
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ pub mod builtin {
335335
/// proxied through this one. `format_args!`, unlike its derived macros, avoids
336336
/// heap allocations.
337337
///
338+
/// You can use the [`fmt::Arguments`] value that `format_args!` returns
339+
/// in `Debug` and `Display` contexts as seen below. The example also shows
340+
/// that `Debug` and `Display` format to the same thing: the interpolated
341+
/// format string in `format_args!`.
342+
///
343+
/// ```rust
344+
/// let display = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
345+
/// let debug = format!("{}", format_args!("{} foo {:?}", 1, 2));
346+
/// assert_eq!("1 foo 2", display);
347+
/// assert_eq!(display, debug);
348+
/// ```
349+
///
338350
/// For more information, see the documentation in [`std::fmt`].
339351
///
340352
/// [`Display`]: ../std/fmt/trait.Display.html

0 commit comments

Comments
 (0)