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

Support a copying read from Unalign<T> where T: !Copy but is FromBytes + IntoBytes #2004

Open
kupiakos opened this issue Nov 1, 2024 · 1 comment
Labels
customer-request Documents customer requests.

Comments

@kupiakos
Copy link
Contributor

kupiakos commented Nov 1, 2024

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 method comes in handy. However, this doesn't work when you have a Ref<&[u8], [Unalign<T>]>, since there's no builtin way to index a Ref<_, [T]>.

It'd be very nice if I could take some &Unalign<T> 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<T> where T: !Copy.

@kupiakos kupiakos added the customer-request Documents customer requests. label Nov 1, 2024
@joshlf
Copy link
Member

joshlf commented Nov 4, 2024

I'm going to make this a child of #1316 - the full solution to this is to support generic types in transmute!, which in turn requires being able to express generic size equality.

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

2 participants