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

#[repr(transparent)] wrapper around [u8] DST #174

Open
bradleyharden opened this issue Feb 19, 2023 · 1 comment
Open

#[repr(transparent)] wrapper around [u8] DST #174

bradleyharden opened this issue Feb 19, 2023 · 1 comment

Comments

@bradleyharden
Copy link

I searched through the issues, but I couldn't find anything related to this use case.

Would it be possible to support the following example in some way? It seems like a natural use of bytemuck::from_bytes, but AnyBitPattern requires both Sized and Copy, so I it's not possible right now. Is handling DSTs too complicated or impossible in the general case? Is this just a situation that will always require manual unsafe?

#[repr(transparent)]
pub struct Slice {
    inner: [u8],
}

impl Slice {
    #[inline]
    fn from_u8_slice(s: &[u8]) -> &Slice {
        unsafe { std::mem::transmute(s) }
    }
}
@Lokathor
Copy link
Owner

This is entirely possible it's just that we haven't quite put in the design work yet. It's not very different from the existing TransparentWrapper stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants