Macro std::writeln

1.0.0 · source ·
macro_rules! writeln {
    ($dst:expr $(,)?) => { ... };
    ($dst:expr, $($arg:tt)*) => { ... };
}
Expand description

将格式化的数据写入到缓冲区,并追加一个换行符。

在所有平台上,新行是一个换行符 (也就是 \n/U+000A),并不包含回车符 (也就是 \r/U+000D)。

有关更多信息,请参见 write!。有关格式字符串语法的信息,请参见 std::fmt

Examples

use std::io::{Write, Result};

fn main() -> Result<()> {
    let mut w = Vec::new();
    writeln!(&mut w)?;
    writeln!(&mut w, "test")?;
    writeln!(&mut w, "formatted {}", "arguments")?;

    assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
    Ok(())
}
Run