Skip to content

Commit 439311d

Browse files
committed
Auto merge of #28049 - steveklabnik:doc_write, r=alexcrichton
2 parents 7dcc4d7 + ef9e542 commit 439311d

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/libcore/macros.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,14 @@ macro_rules! try {
168168
})
169169
}
170170

171-
/// Use the `format!` syntax to write data into a buffer of type `&mut Write`.
172-
/// See `std::fmt` for more information.
171+
/// Use the `format!` syntax to write data into a buffer.
172+
///
173+
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
174+
///
175+
/// See [`std::fmt`][fmt] for more information on format syntax.
176+
///
177+
/// [fmt]: fmt/index.html
178+
/// [write]: io/trait.Write.html
173179
///
174180
/// # Examples
175181
///
@@ -179,14 +185,34 @@ macro_rules! try {
179185
/// let mut w = Vec::new();
180186
/// write!(&mut w, "test").unwrap();
181187
/// write!(&mut w, "formatted {}", "arguments").unwrap();
188+
///
189+
/// assert_eq!(w, b"testformatted arguments");
182190
/// ```
183191
#[macro_export]
184192
macro_rules! write {
185193
($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
186194
}
187195

188-
/// Equivalent to the `write!` macro, except that a newline is appended after
189-
/// the message is written.
196+
/// Use the `format!` syntax to write data into a buffer, appending a newline.
197+
///
198+
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
199+
///
200+
/// See [`std::fmt`][fmt] for more information on format syntax.
201+
///
202+
/// [fmt]: fmt/index.html
203+
/// [write]: io/trait.Write.html
204+
///
205+
/// # Examples
206+
///
207+
/// ```
208+
/// use std::io::Write;
209+
///
210+
/// let mut w = Vec::new();
211+
/// writeln!(&mut w, "test").unwrap();
212+
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
213+
///
214+
/// assert_eq!(&w[..], "test\nformatted arguments\n".as_bytes());
215+
/// ```
190216
#[macro_export]
191217
#[stable(feature = "rust1", since = "1.0.0")]
192218
macro_rules! writeln {

0 commit comments

Comments
 (0)