-
Notifications
You must be signed in to change notification settings - Fork 13.4k
core: add {Imm,M}utablePrimitiveSlice trait #19241
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
Conversation
r? @aturon |
Lets eligible slices be converted to a slice of bytes. Abstracts out some sensible unsafe behavior from `rust-image`.
CC @alexcrichton on if we want to take the opportunity to use the new raw tooling to do explicit lifetime management here. |
|
||
/// This uses `Primitive` instead of `Copy` because otherwise one would be | ||
/// able to write invalid enum discriminants or bools, which is unsafe. | ||
impl<T: Primitive> MutablePrimitiveSlice for [T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsafe, because Primitive
is just a trait, and can be implemented for new types (e.g. new enums that you create). Also note that Primitive
has been deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same above I believe as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also exposing the underlying endian-ness of the system (not portable), which may want to at least be mentioned in the documentation if we move forward with this.
Unfortunately, I doubt that there is a way to make the mutable part here safe while providing a blanket In general, before we bring this into the standard library, it would be helpful to have more information about the use cases (and better yet, some evidence that many clients would benefit). This is something that can easily be provided in an external library, so it should only be brought into |
@aturon Ah, yes, I forgot about extension impls. Quite unfortunate, really. It'd be nice to be able to represent a closed set of types. (Closed in the extension meaning, not topological). |
@aturon The use cases in I've begun a casual audit of unsafe code used by various libraries, and this is a core piece of |
Fix sysroot crate-graph construction not mapping crate-ids for proc-macros
Lets eligible slices be converted to a slice of bytes. Abstracts out some
sensible unsafe behavior from
rust-image
.