Skip to content
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

Returned Writer might fail #463

Open
vorner opened this issue Jan 16, 2021 · 0 comments
Open

Returned Writer might fail #463

vorner opened this issue Jan 16, 2021 · 0 comments

Comments

@vorner
Copy link
Contributor

vorner commented Jan 16, 2021

The documentation of the BufMut::writer claims that the returned writer will never fail:

This function returns a new value which implements Write by adapting the Write trait functions to the BufMut trait functions. Given that BufMut operations are infallible, none of the Write functions will return with Err.

This is, however, not true, it may error on not enough capacity in the buffer:

use std::io::Write;
use bytes::BufMut;

fn main() {
    let mut buffer = [0; 10];
    let mut w = buffer.writer();
    w.write_all(b"Hello world").unwrap();
}

I believe a similar can be achieved with the reader's read_exact and its documentation makes a similar claim.

To be clear, I think the actual behaviour is expected and the only reasonable way it could act. But maybe the documentation should be adjusted to claim something little weaker (like, returning errors related to end of buffer only)?

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

No branches or pull requests

1 participant