google / google/zerocopy

Features to support indexmap

Open
#1,187 0 comments 0 reactions 0 assignees View on GitHub
customer-request
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

## Container transmutation (#114) + safe transmute

With container transmutation + safe transmute, we could support `[Bucket] -> Slice` transmutation, e.g. used in [this code](https://github.com/indexmap-rs/indexmap/blob/3f0fffb85b99a2a37bbee363703f8509dd03e2d7/src/set/slice.rs#L18C1-L38C2):

```rust
#[repr(transparent)]
pub struct Slice {
pub(crate) entries: [Bucket],
}

// SAFETY: `Slice` is a transparent wrapper around `[Bucket]`,
// and reference lifetimes are bound together in function signatures.
#[allow(unsafe_code)]
impl Slice {
pub(super) const fn from_slice(entries: &[Bucket]) -> &Self {
unsafe { &*(entries as *const [Bucket] as *const Self) }
}

pub(super) fn from_boxed(entries: Box<[Bucket]>) -> Box {
unsafe { Box::from_raw(Box::into_raw(entries) as *mut Self) }
}

fn into_boxed(self: Box) -> Box<[Bucket]> {
unsafe { Box::from_raw(Box::into_raw(self) as *mut [Bucket]) }
}
}
```

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.