Skip to content

Commit 0e6f898

Browse files
committed
Auto merge of #57195 - czipperz:mention_ToString_in_std_fmt_docs, r=SimonSapin
Mention ToString in std::fmt docs I believe this should be added because `x.to_string()` is preferred over `format!("{}", x)` as the recommended way to convert a value to a string. `std::fmt` and the `format` macro is where people look for documentation about this, and thus we should include references to this preferred functions there. Resolves #55065
2 parents 171c1fc + 56d6ff0 commit 0e6f898

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/liballoc/fmt.rs

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
//! will then parse the format string and determine if the list of arguments
2828
//! provided is suitable to pass to this format string.
2929
//!
30+
//! To convert a single value to a string, use the [`to_string`] method. This
31+
//! will use the [`Display`] formatting trait.
32+
//!
3033
//! ## Positional parameters
3134
//!
3235
//! Each formatting argument is allowed to specify which value argument it's
@@ -487,6 +490,7 @@
487490
//! [`write!`]: ../../std/macro.write.html
488491
//! [`Debug`]: trait.Debug.html
489492
//! [`format!`]: ../../std/macro.format.html
493+
//! [`to_string`]: ../../std/string/trait.ToString.html
490494
//! [`writeln!`]: ../../std/macro.writeln.html
491495
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
492496
//! [`std::io::Write`]: ../../std/io/trait.Write.html

src/liballoc/macros.rs

+5
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ macro_rules! vec {
7373
/// The same convention is used with [`print!`] and [`write!`] macros,
7474
/// depending on the intended destination of the string.
7575
///
76+
/// To convert a single value to a string, use the [`to_string`] method. This
77+
/// will use the [`Display`] formatting trait.
78+
///
7679
/// [fmt]: ../std/fmt/index.html
7780
/// [`print!`]: ../std/macro.print.html
7881
/// [`write!`]: ../std/macro.write.html
82+
/// [`to_string`]: ../std/string/trait.ToString.html
83+
/// [`Display`]: ../std/fmt/trait.Display.html
7984
///
8085
/// # Panics
8186
///

0 commit comments

Comments
 (0)