-
Notifications
You must be signed in to change notification settings - Fork 80
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
[ptr] Add TransparentWrapper #958
Conversation
7602838
to
edf0f78
Compare
TransparentWrapper is implemented for wrapper types which transparently wrap other types (with the same layout and `UnsafeCell` ranges). This allows us to express a number of conversions more generically, and write less location-specific `unsafe` code.
edf0f78
to
2234f17
Compare
// SAFETY: `Wrapping<T>` has only one field, which is `pub` [2]. We are also | ||
// guaranteed per [1] (from the comment above) that `Wrapping<T>` has the | ||
// same layout as `T`. The only way for both of these to be true | ||
// simultaneously is for `Wrapping<T>` to have the same bit validity as `T`. | ||
// In particular, in order to change the bit validity, one of the following | ||
// would need to happen: | ||
// - `Wrapping` could change its `repr`, but this would violate the layout | ||
// guarantee. | ||
// - `Wrapping` could add or change its fields, but this would be a | ||
// stability-breaking change. | ||
// | ||
// [2] https://doc.rust-lang.org/core/num/struct.Wrapping.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jswrenn Following up from our conversation offline - you had more suggestions for this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine,
// SAFETY: `Wrapping<T>` has only one field, which is `pub` [2]. We are also | ||
// guaranteed per [1] (from the comment above) that `Wrapping<T>` has the | ||
// same layout as `T`. The only way for both of these to be true | ||
// simultaneously is for `Wrapping<T>` to have the same bit validity as `T`. | ||
// In particular, in order to change the bit validity, one of the following | ||
// would need to happen: | ||
// - `Wrapping` could change its `repr`, but this would violate the layout | ||
// guarantee. | ||
// - `Wrapping` could add or change its fields, but this would be a | ||
// stability-breaking change. | ||
// | ||
// [2] https://doc.rust-lang.org/core/num/struct.Wrapping.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine,
No description provided.