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
This commit is contained in:
bors 2018-12-30 07:12:13 +00:00
commit 0e6f8987aa
2 changed files with 9 additions and 0 deletions

View File

@ -27,6 +27,9 @@
//! will then parse the format string and determine if the list of arguments
//! provided is suitable to pass to this format string.
//!
//! To convert a single value to a string, use the [`to_string`] method. This
//! will use the [`Display`] formatting trait.
//!
//! ## Positional parameters
//!
//! Each formatting argument is allowed to specify which value argument it's
@ -487,6 +490,7 @@
//! [`write!`]: ../../std/macro.write.html
//! [`Debug`]: trait.Debug.html
//! [`format!`]: ../../std/macro.format.html
//! [`to_string`]: ../../std/string/trait.ToString.html
//! [`writeln!`]: ../../std/macro.writeln.html
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
//! [`std::io::Write`]: ../../std/io/trait.Write.html

View File

@ -73,9 +73,14 @@ macro_rules! vec {
/// The same convention is used with [`print!`] and [`write!`] macros,
/// depending on the intended destination of the string.
///
/// To convert a single value to a string, use the [`to_string`] method. This
/// will use the [`Display`] formatting trait.
///
/// [fmt]: ../std/fmt/index.html
/// [`print!`]: ../std/macro.print.html
/// [`write!`]: ../std/macro.write.html
/// [`to_string`]: ../std/string/trait.ToString.html
/// [`Display`]: ../std/fmt/trait.Display.html
///
/// # Panics
///