Skip to content
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

Features to support indexmap #1187

Open
joshlf opened this issue May 4, 2024 · 0 comments
Open

Features to support indexmap #1187

joshlf opened this issue May 4, 2024 · 0 comments
Labels
customer-request Documents customer requests.

Comments

@joshlf
Copy link
Member

joshlf commented May 4, 2024

Container transmutation (#114) + safe transmute

With container transmutation + safe transmute, we could support [Bucket<T>] -> Slice<T> transmutation, e.g. used in this code:

#[repr(transparent)]
pub struct Slice<T> {
    pub(crate) entries: [Bucket<T>],
}

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

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

    fn into_boxed(self: Box<Self>) -> Box<[Bucket<T>]> {
        unsafe { Box::from_raw(Box::into_raw(self) as *mut [Bucket<T>]) }
    }
}
@joshlf joshlf added the customer-request Documents customer requests. label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-request Documents customer requests.
Projects
None yet
Development

No branches or pull requests

1 participant