In format!(..)
, print!(..)
, println!(..)
etc. it's easy enough to insert values in various formats, however the docs show no way of adding an OS specific newline (e.g. '\n'
in unices/MacOS X, "\r\n"
on Windows). Is there such a format specifier? If not, how should one put newlines in their formatted strings/outputs?
I don't believe so.
That said, with the exception of Notepad, just about everything on Windows has long since learned that \n
is as much a newline as \r\n
. In fact, the only other time I have line ending issues is badly ported UNIX software that refuses to believe in the existence of \r\n
newlines.
In other words, unless you have a specific reason for doing so, just stick to \n
.
If you do have a specific reason, it's probably simplest to define a NL
constant somewhere (I couldn't find one in the stdlib):
#[cfg(windows)] pub const NL: &'static str = "\r\n";
#[cfg(not(windows))] pub const NL: &'static str = "\n";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With