Skip to content

Commit

Permalink
Allow writeln! without arguments, in symmetry with println!
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Dec 19, 2016
1 parent 10271ea commit a0b346a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/libcore/macros.rs
Expand Up @@ -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
Expand All @@ -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"))
);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/macros.rs
Expand Up @@ -112,7 +112,7 @@ macro_rules! print {
/// # Examples
///
/// ```
/// println!();
/// println!(); // prints just a newline
/// println!("hello there!");
/// println!("format {} arguments", "some");
/// ```
Expand Down

0 comments on commit a0b346a

Please sign in to comment.