RFC 2835: Safe transmute WG

lang ()

Summary

To form a project group with the purpose of designing subsequent RFCs around the topic of safe transmute between types.

Motivation

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.

Details of the safe transmute project group

Repository

Initial shepherds:

Lang team liaisons:

Charter

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.

Constraints and considerations

In its work, the project-group should consider various constraints and considerations:

Participation in the project group

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.

Drawbacks

Prior art

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.

Unresolved questions and Future possibilities

Since this RFC merely formalizes the creation of the project group, it intentionally leaves all technical details within the project's scope unresolved.

Future possibilities

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.