Allow writeln! without arguments, in symmetry with println!

This commit is contained in:
Tobias Bucher
2016-12-19 16:57:23 +01:00
parent 10271ea24f
commit a0b346a349
2 changed files with 6 additions and 2 deletions

View File

@@ -404,10 +404,11 @@ macro_rules! write {
/// use std::io::Write;
///
/// let mut w = Vec::new();
/// writeln!(&mut w).unwrap();
/// writeln!(&mut w, "test").unwrap();
/// writeln!(&mut w, "formatted {}", "arguments").unwrap();
///
/// assert_eq!(&w[..], "test\nformatted arguments\n".as_bytes());
/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
/// ```
///
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
@@ -427,6 +428,9 @@ macro_rules! write {
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! writeln {
($dst:expr) => (
write!($dst, "\n")
);
($dst:expr, $fmt:expr) => (
write!($dst, concat!($fmt, "\n"))
);

View File

@@ -112,7 +112,7 @@ macro_rules! print {
/// # Examples
///
/// ```
/// println!();
/// println!(); // prints just a newline
/// println!("hello there!");
/// println!("format {} arguments", "some");
/// ```