Skip to content

Commit c34f533

Browse files
authored
Rollup merge of rust-lang#40934 - SamWhited:improve_write_writeln_docs, r=steveklabnik
Improve the docs for the write and writeln macros This change reduces duplication by linking the documentation for `writeln!` to `write!`. It also restructures the `write!` documentation to read in a more logical manner (I hope; feedback would be welcome). Updates rust-lang#29329, rust-lang#29381
2 parents d36b24d + b03edb4 commit c34f533

File tree

1 file changed

+16
-38
lines changed

1 file changed

+16
-38
lines changed

src/libcore/macros.rs

+16-38
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,20 @@ macro_rules! try {
337337

338338
/// Write formatted data into a buffer
339339
///
340-
/// This macro accepts a 'writer' (any value with a `write_fmt` method), a format string, and a
341-
/// list of arguments to format.
340+
/// This macro accepts a format string, a list of arguments, and a 'writer'. Arguments will be
341+
/// formatted according to the specified format string and the result will be passed to the writer.
342+
/// The writer may be any value with a `write_fmt` method; generally this comes from an
343+
/// implementation of either the [`std::fmt::Write`] or the [`std::io::Write`] trait. The macro
344+
/// returns whatever the 'write_fmt' method returns; commonly a [`std::fmt::Result`], or an
345+
/// [`io::Result`].
342346
///
343-
/// The `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write]
344-
/// or [`std::io::Write`][io_write] traits. The term 'writer' refers to an implementation of one of
345-
/// these two traits.
347+
/// See [`std::fmt`] for more information on the format string syntax.
346348
///
347-
/// Passed arguments will be formatted according to the specified format string and the resulting
348-
/// string will be passed to the writer.
349-
///
350-
/// See [`std::fmt`][fmt] for more information on format syntax.
351-
///
352-
/// `write!` returns whatever the 'write_fmt' method returns.
353-
///
354-
/// Common return values include: [`fmt::Result`][fmt_result], [`io::Result`][io_result]
355-
///
356-
/// [fmt]: ../std/fmt/index.html
357-
/// [fmt_write]: ../std/fmt/trait.Write.html
358-
/// [io_write]: ../std/io/trait.Write.html
359-
/// [fmt_result]: ../std/fmt/type.Result.html
360-
/// [io_result]: ../std/io/type.Result.html
349+
/// [`std::fmt`]: ../std/fmt/index.html
350+
/// [`std::fmt::Write`]: ../std/fmt/trait.Write.html
351+
/// [`std::io::Write`]: ../std/io/trait.Write.html
352+
/// [`std::fmt::Result`]: ../std/fmt/type.Result.html
353+
/// [`io::Result`]: ../std/io/type.Result.html
361354
///
362355
/// # Examples
363356
///
@@ -396,27 +389,12 @@ macro_rules! write {
396389
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
397390
/// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
398391
///
399-
/// This macro accepts a 'writer' (any value with a `write_fmt` method), a format string, and a
400-
/// list of arguments to format.
401-
///
402-
/// The `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write]
403-
/// or [`std::io::Write`][io_write] traits. The term 'writer' refers to an implementation of one of
404-
/// these two traits.
405-
///
406-
/// Passed arguments will be formatted according to the specified format string and the resulting
407-
/// string will be passed to the writer, along with the appended newline.
408-
///
409-
/// See [`std::fmt`][fmt] for more information on format syntax.
410-
///
411-
/// `write!` returns whatever the 'write_fmt' method returns.
392+
/// For more information, see [`write!`]. For information on the format string syntax, see
393+
/// [`std::fmt`].
412394
///
413-
/// Common return values include: [`fmt::Result`][fmt_result], [`io::Result`][io_result]
395+
/// [`write!`]: macro.write.html
396+
/// [`std::fmt`]: ../std/fmt/index.html
414397
///
415-
/// [fmt]: ../std/fmt/index.html
416-
/// [fmt_write]: ../std/fmt/trait.Write.html
417-
/// [io_write]: ../std/io/trait.Write.html
418-
/// [fmt_result]: ../std/fmt/type.Result.html
419-
/// [io_result]: ../std/io/type.Result.html
420398
///
421399
/// # Examples
422400
///

0 commit comments

Comments
 (0)