-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
rust/src/libstd/io/buffered.rs
Line 451 in eeaf497
| inner: Option<W>, |
BufWriter doesn't really need to hold its inner writer as an Option; it seems like the only reason it does so is to make it easier to call into_inner, here:
rust/src/libstd/io/buffered.rs
Lines 648 to 653 in eeaf497
| pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> { | |
| match self.flush_buf() { | |
| Err(e) => Err(IntoInnerError(self, e)), | |
| Ok(()) => Ok(self.inner.take().unwrap()), | |
| } | |
| } |
While it's unfortunate to add unsafe, there's already some in buffered.rs, and it seems like the better choice here would be to use ptr::read and mem::forget, especially because this method is probably infrequently used, and making this change would remove the numerous unwraps that litter the BufWriter implementation.
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.