-
Notifications
You must be signed in to change notification settings - Fork 19
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
as_slice
/into_slice
for IoSlice
/IoSliceMut
#93
Comments
I've been trying to use vectored I/O for some performant networking use cases, and having a feature like this would really help--there's just no good way to update slice indices right now. |
We discussed this in the libs meetup. This looks fine, except that Feel free to open a tracking issue and open a PR to rust-lang/rust to add this as an unstable feature. |
…again, r=<try> Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: rust-lang/libs-team#93 Based on a623c52 (CC `@mpdn)` and rust-lang#111277 (CC `@Lucretiel).` Closes: rust-lang#124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? `@ghost`
…again, r=<try> Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: rust-lang/libs-team#93 Based on a623c52 (CC `@mpdn)` and rust-lang#111277 (CC `@Lucretiel).` Closes: rust-lang#124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? `@ghost`
…s-again, r=cuviper Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: rust-lang/libs-team#93 Tracking issue: rust-lang#132818 Based on a623c52 (CC `@mpdn)` and rust-lang#111277 (CC `@Lucretiel).` Closes: rust-lang#124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? libs
Rollup merge of rust-lang#132790 - aDotInTheVoid:ioslice-asslice-rides-again, r=cuviper Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: rust-lang/libs-team#93 Tracking issue: rust-lang#132818 Based on a623c52 (CC `@mpdn)` and rust-lang#111277 (CC `@Lucretiel).` Closes: rust-lang#124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? libs
Proposal
Add an
as_slice
onIoSlice
to go from&IoSlice<'a>
to&'a [u8]
.Add an
into_slice
onIoSliceMut
to go fromIoSliceMut<'a>
to&'a mut [u8]
.Problem statement
Using vectored IO (eg.
write_vectored
) is close to impossible to do correctly due to the difficulty of slicing/advancingIoSlice
Consider something like this:
The issue here is that
write_vectored
may only do a partial write of a slices. To ensure we write all data we need to advance the slices. Dealing with this is a little bit more annoying than ordinary writes, but we might try something like this:But this fails to compile! The problem is that in
IoSlice::new(&buf[0][written..])
we try to slice theIoSlice
. This uses theDeref
trait implemented on theIoSlice
, but this ends up borrowing the IO slice. Thus we cannot modifybuf
as we are also borrowing data stored in it. Instead, if we simply had anas_slice
as above, we could simply write that asIoSlice::new(&buf[0].as_slice()[written..])
instead.There has been a few similar solutions to this problem, such as rust-lang/rust#62726 and rust-lang/rust#70436. These have sort of stalled, in part due to the resulting signatures ending up being sort of odd in cases where we want to advance a slice of
IoSlice
s. I think the above proposal is simpler and more basic as it allows the user to construct functions likewrite_all_vectored
,advance
, oradvance_slices
in ordinary safe Rust.Motivation, use-cases
None found - I haven't actually been able to find any applications doing vectored IO in Rust. Only vectored IO I have found has been wrapping
write_vectored
and the like: https://github.com/search?l=Rust&p=2&q=%22write_vectored%22&type=CodeSolution sketches
Already have it implemented here: https://github.com/rust-lang/rust/compare/master...mpdn:rust:master?expand=1
Links and related work
Write::write_all_vectored
rust#70436The text was updated successfully, but these errors were encountered: