Lokathor/bytemuck

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

bradleyharden opened this issue · 1 comments

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) }
    }
}

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.