Skip to content

Remove Option<W> in BufWriter #72925

Closed
@Lucretiel

Description

@Lucretiel

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:

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

No one assigned

    Labels

    C-enhancementCategory: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions