Support a copying read from `Unalign<T>` where `T: !Copy` but is `FromBytes + IntoBytes`
Open
customer-request
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
When working with generic code where we don't want to require `Copy` for large structs but is still constructed from unaligned bytes, the [`Ref::read`](https://docs.rs/zerocopy/latest/zerocopy/struct.Ref.html#method.read) method comes in handy. However, this doesn't work when you have a `Ref<&[u8], [Unalign]>`, since there's no builtin way to index a `Ref<_, [T]>`.
It'd be very nice if I could take some `&Unalign` and copy out a `T` where `T: FromBytes + IntoBytes`. This would be infallible shorthand for `T::read_from_bytes(unaligned_val.as_bytes()).unwrap()`. I'm not aware of an infallible way to copy out of an `Unalign where T: !Copy`.
Contributor guide
Assessment
This issue has not been assessed yet.