Skip to content

Conversation

@alexcrichton
Copy link
Member

Now that we can call flush() in destructors, I think that it's appropriate for stdout/stderr to return buffered writers by default.

This doesn't enable certain functionality like a buffered stdin does, but it's what you want 90% of the time for performance reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for wrapping the writer in Option? As near as I can tell, it will always be a Some.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't move out of an object that has a destructor, so in order to support the unwrap() method this needs an Option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I didn't actually realize that. I guess that makes sense, as the destructor would need to be able to figure out that the field had been moved.

It's still not entirely clear what should happen if there was an error when
flushing, but I'm deferring that decision to rust-lang#12628. I believe that it's crucial
for the usefulness of buffered writers to be able to flush on drop. It's just
too easy to forget to flush them in small one-off use cases.

cc rust-lang#12628
Similarly to rust-lang#12422 which made stdin buffered by default, this commit makes the
output streams also buffered by default. Now that buffered writers will flush
their contents when they are dropped, I don't believe that there's no reason why
the output shouldn't be buffered by default, which is what you want in 90% of
cases.

As with stdin, there are new stdout_raw() and stderr_raw() functions to get
unbuffered streams to stdout/stderr.
bors added a commit that referenced this pull request Mar 1, 2014
Now that we can call `flush()` in destructors, I think that it's appropriate for stdout/stderr to return buffered writers by default.

This doesn't enable certain functionality like a buffered stdin does, but it's what you want 90% of the time for performance reasons.
@bors bors closed this Mar 1, 2014
@bors bors merged commit 2cb83fd into rust-lang:master Mar 1, 2014
@alexcrichton alexcrichton deleted the flush-buffered branch March 3, 2014 00:12
@gwillen
Copy link
Contributor

gwillen commented Mar 3, 2014

This is a driveby comment from someone with no real stake, so please give it only as much thought as it deserves, which is not much:

It might make sense for stderr to be unbuffered by default. This is the case in Perl, Python, Ruby, and C, and probably other languages (those are the only ones I checked.) I'm sure there are good reasons for this beyond the ones I will list here, but mine are: In the event of a crash, you want to have the most up-to-date output from stderr, and unlike stdout you typically aren't ever sending huge volumes of data through stderr in a potentially performance-critical way (such that default-buffering is beneficial enough to outweigh the surprise it causes.)

flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 18, 2024
Correct parentheses for [`needless_borrow`] suggestion

This fixes rust-lang#12268

Clippy no longer adds unnecessary parentheses in suggestions when the expression is part of a tuple.

---

changelog: Fix [`needless_borrow`] unnecessary parentheses in suggestion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants