Logo

Programming-Idioms

History of Idiom 59 > diff from v5 to v6

Edit summary for version 6 by :
↷

Version 5

2015-07-31, 20:48:02

Version 6

2015-08-19, 18:06:48

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;
Code
writeln!(&mut stderr(), "{} is negative", x).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