-
Notifications
You must be signed in to change notification settings - Fork 105
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
Make the inner type wrapped in Unalign
public
#836
Comments
This allows for directly writing to the field safely. Since Rust ensures that unsafe uses of this field require `unsafe`, we should additionally consider deprecating many of the methods of `Unalign`. Fixes #836
This allows for directly writing to the field safely. Since Rust ensures that unsafe uses of this field require `unsafe`, we should additionally consider deprecating many of the methods of `Unalign`. Fixes #836
I'm concerned that this will back us into a corner. In particular, there's a chance that we may want to support unsized I agree that there's a minor ergonomic benefit with making the inner field public, but are there any patterns that can't be expressed with our existing API and methods? If it's just an ergonomic thing, I'm inclined to not do this right now, but if it's an expressibility issue, then that's a different story. |
Note that #1076 implements this. I've closed it, but we can re-open if we decide to move forward with this. |
Merging #1860 into this Original text by @kupiakos: This enables full field reference projection for fields that are sufficiently aligned and field read/write access for all fields and subfields. This must be done through direct struct field access for the compiler to accept it. Sample use caseSay the input buffer you receive has bytes in the format of In order to access specific unaligned fields safely, you need one of the following:
Currently, the workaround is to declare your own It might be worth gating the inner Additionally, if we add |
This is not exactly a customer request since I'm not using this crate currently, but I was looking on the docs and I wondered why won't you make the inner field of
Unalign
public?Usually when prefer to make newtype's field private, but in this case making it public has a big advantage: we cannot make a reference to it and so we cannot expose it in a non-copying way, but if it is public the compiler allows reads/writes to fields of it as long as we never take a reference and only read/write directly. This can make working with this type more comfortable.
The text was updated successfully, but these errors were encountered: