Logo

Programming-Idioms

History of Idiom 59 > diff from v38 to v39

Edit summary for version 39 by Debaran:
[Rust] More idiomatic way
↷

Version 38

2018-05-27, 20:11:01

Version 39

2019-02-02, 05:16:06

Idiom #59 Write to standard error stream

Print the message "x is negative" to standard error (stderr), with integer x value substitution (e.g. "-2 is negative").

Idiom #59 Write to standard error stream

Print the message "x is negative" to standard error (stderr), with integer x value substitution (e.g. "-2 is negative").

Imports
use std::io::stderr;
use std::io::Write;
Imports
Code
writeln!(&mut stderr(), "{} is negative", x).unwrap();
Code
eprintln!("{} is negative", x);
Comments bubble
Please note that writing to `stderr` can fail—therefor the `unwrap`.
Comments bubble
Please note that writing to `stderr` can fail—therefor the `unwrap`.
Origin
http://stackoverflow.com/a/27590832/1254484
Demo URL
https://play.rust-lang.org/?code=use%20std%3A%3Aio%3A%3Astderr%3B%0Ause%20std%3A%3Aio%3A%3AWrite%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%20-2%3B%0A%20%20%20%20writeln!(%26mut%20stderr()%2C%20%22%7B%7D%20is%20negative%22%2C%20x).unwrap()%3B%0A%7D&version=stable