Tracking issue for Write::write_all_vectored
· Issue #70436 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
This is a tracking issue for io::Write::write_all_vectored
.
Feature gate: #![feature(write_all_vectored)]
.
Steps:
- Implement the RFC (Add io::Write::write_all_vectored #70612).
- Stabilization PR.
Unresolved questions:
- Can we improve the API? Currently the method takes the
IoSlice
s as mutable slice and modifies them. This is a pretty unusual and potentially error-prone API. We could either find a way to not mutate the argument or to enforce (via the type system) the argument can't be used by the user afterwards. Or we can decide that such an unusual API is fine for this rather low level method.
Original issue:
In the io::Write
trait we've got the helpful write_all
method, which calls write
in a loop to write all bytes. However there is no such function for write_vectored
. I would suggest adding a function called write_all_vectored
to performance such a task.
A possible implementation. Note that bufs
is a mutable slice, also see the discussion in https://github.com/rust-lang/futures-rs/pull/1741/files. On the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=872e9d973bd8101e7724292f87a82869.
pub trait Write { // ...
fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
while !bufs.is_empty() {
match self.write_vectored(bufs) {
Ok(0) => {
return Err(Error::new(
ErrorKind::WriteZero,
"failed to write whole buffer",
));
}
Ok(n) => bufs = IoSlice::advance(mem::replace(&mut bufs, &mut []), n),
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
}
Ok(())
}
}
Related: rust-lang/futures-rs#1741
/cc @cramertj