google / google/zerocopy

Support prefix transmutes in `transmute!` et al

Open
#1,852 1 comment 1 reaction 0 assignees View on GitHub
experience-hard help wanted
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

### Syntax

We should be able to add special syntax so that existing uses of `transmute!` are unaffected, while users are able to opt-in to prefix transmute behavior:

```rust
// Current behavior, remains the default.
transmute!(a);
// Opt-in to prefix transmutation (exact syntax to be bikeshedded)
transmute!(@prefix a);
```

### Design

Currently, we require that `mem::transmute::()` compiles, which ensures that `size_of::() == size_of::()`. If we instead introduce a `union MaxSizesOf` type, then we can instead require that `mem::transmute::, T>()` compiles. This ensures that `size_of::() >= size_of::()`, which ensures that it's sound to perform a prefix transmute from `T` to `U`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.