Open
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
Metadata
Metadata
Assignees
Labels
Area: `std::io`, `std::fs`, `std::net` and `std::path`Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCLibs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.