-
Notifications
You must be signed in to change notification settings - Fork 677
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
RFC: Use byte slices directly in place of IoVec #263
Comments
@arcnmx any thoughts here? This seems likke the kind of thing you'd have opinions on. :-) |
My thought is yes that makes for a better API, however, I'd be wary about whether the layout of slices is well-defined by the language or if we're just relying on implementation details. So I like the proposed changes, but I'm not sure if they'd be relying on undefined or underspecified behaviour. Changing it to |
This makes sense. I'll try and bug some people on #rust-internals to see if my evil plan could be ok. |
As a safety feature if we get CI on more platforms, we could have a test that creates a byte slice, transmutes to |
Link to the tracking issue for that type and the representation being stable: rust-lang/rust#27751 Also, I made a post on the users forum: https://users.rust-lang.org/t/how-can-i-feel-safe-in-doing-terribly-unsafe-things-like-relying-on-slice-layout/4857 |
The answers to the users forum post convinced me this would be a bad idea. Arguments against:
The only thing going for it is a cute convenience on some number of platforms. |
Summary
Make using
pread
et al nicer by getting rid of a special purpose struct and using a ubiquitous type instead.Motivation
Using
IoVec
in nix is a little cumbersome. At present, in nix, theIoVec
struct is defined:The C
struct iovec
is defined:This is pretty much equivalent to
&[u8]
. Seestd::raw::Slice
:However, the
T
type parameter is never used as anything other than[u8]
, and there is no way to even construct one with any other type.Given that the C
struct iovec
is effectively a slice, and that it exists because C lacks slices, I propose we use slices in its place for the Rust interface.Examples
Signatures before:
After:
If you want to see what it would look like, I've got a partial replacement here: kamalmarhubi@44825ba
The modified tests pass.
Drawbacks
We're relying on a semi-coincidental layout equivalence. This makes me a bit uneasy.
Alternatives
IoVec
only store byte slices.The text was updated successfully, but these errors were encountered: