lang ()
project-safe-transmute
To form a project group with the purpose of designing subsequent RFCs around the topic of safe transmute between types.
std::mem::transmute
with safe alternatives.
Transmuting one type to another type and vice versa in Rust is extremely dangerous --- so much so that the docs for std::mem::transmute are essentially a long list of how to avoid doing so. However, transmuting is often times necessary especially in lower level contexts where copy of bytes is prohibitively expensive. For instance, in extremely performance-sensitive use cases, it may be necessary to transmute from bytes instead of explicitly copying bytes from a buffer into a struct.
Because of this fact, many external crates have been developed to tackle this issue, but no single crate has managed to solidify itself as a clear favorite in this space. Additionally, while it is possible to improve on unsafe transmute considerably in libraries, having such facilities in the standard library opens up the possibility of bringing safe constructs to even more currently unsafe features.
For these reasons, we plan on learning from the prior art to implement a standard way of transmuting types in a safe way.
Initial shepherds:
Lang team liaisons:
The safe transmute project group has the following initial scope:
Once this scope has been reached, the team may continue working on features that are natural extensions of safe transmute like safe reading on union fields.
In its work, the project-group should consider various constraints and considerations:
Like any Rust group, the safe transmute project group intends to operate in a public and open fashion and welcomes participation. Visit the repository for more details.
The formation of the project group was first discussed in the FFI unwind project group RFC. As is state in that RFC, this working group can be considered a precursor to the current "shepherded project group" proposal.
Since this RFC merely formalizes the creation of the project group, it intentionally leaves all technical details within the project's scope unresolved.
The project group will start with a fairly limited scope, but if the initial effort to design and stabilize APIs for safe transmute between types, there is at least one other area that can be expanded upon by this group: safe reading of union fields.