-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macro for printing to stderr #1078
Comments
+1 |
+1 |
+1 |
This would be very useful. Most programs require writing to standard error and it'd be nice if the community could standardize on a macro for this. |
Let's go beyond "wouldn't it be nice if..." and further justify and bring up additional considerations for the introduction of this feature. I believe the lack of such a macro encourages (even if only by omission) the use of standard output for diagnostic purposes, which for the end-user degrades user experience and weakens the semantic power of having both streams available. Imagine my surprise when I redirect the output of some (thus far imaginary) utility written in Rust to a file, and later discover that the file simply says "Wrong arguments"! One might argue that the choice of standard error over standard output is one made by the programmer — and I can not and will not disagree with this. But as programmers, we expect our tools and their documentation to guide us toward the semantically correct choice (arguably more so with Rust than usual). We should consider carefully:
|
I agree this may be nice. In essentially every CLI tool I've written, I've defined macros like |
Is there a crate that implements this (and only this)? I suspect a strong motivation for moving to std would be such a crate with wide usage. |
@nrc, I personally wouldn't bother with such a crate because such a macro is trivial to define. What's missing is a standardized name for such a macro, and the guidance for new users to learn how to properly separate debug and normal (stderr and stdout) statements as I mentioned in an earlier comment. (This guidance is currently missing from all documentation, and we happily tell those learning Rust that It seems to me that, depending on the outcome of this thread, it may be a good idea to have a follow-up RFC that more formally discusses the macro's name and use cases, in addition to how it should be introduced to those learning Rust. |
I think an in-standard solution to this is generally a good idea (standardized name is a big part of this), and would like to request that whatever the solution is, an output similar to panics "message at foobar.rs:230 However, that aside, I also don't want a solution in the standard library. Rust seems to go with the strategy of trying to push programmers into "doing the right thing," which most of the time means |
Yeah I sometimes wish print* just didn't exist and everybody used log. |
I find myself printing to stderr quite often by creating an stderr variable and writing to it with the // Prints to standard error
println!(stderr "Message to print to stderr");
// Prints to standard output
println!(stdout "Message to print to stdout");
// Prints to standard output
println!("Message to print to stdout"); It wouldn't break any existing code -- just extends what kinds of inputs that the print macros can support. |
This feature was recently merged in. See rust-lang/rust#40528. |
This should be closed, |
I see people using http://is.gd/8TYNHp so much, that I wonder if it should be in the standard library.
The text was updated successfully, but these errors were encountered: