-
Notifications
You must be signed in to change notification settings - Fork 33
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
rework CastPtr
, CastConstPtr
, BoxCastPtr
, ArcCastPtr
#353
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpu
commented
Oct 13, 2023
cpu
commented
Oct 13, 2023
cpu
commented
Oct 13, 2023
fbeec7f
to
b13c99d
Compare
I like Castable a lot!
|
This commit reworks the existing `CastPtr`, `CastConstPtr`, `BoxCastPtr`, and `ArcCastPtr` traits into a new `Castable` trait with an associated `Ownership`, constrained to be a type implementing the new `OwnershipMarker` trait. Three implementations of this `OwnershipMarker` trait are offered: `OwnershipBox`, `OwnershipArc` and `OwnershipRef`. The net result is that the type system is now able to enforce our invariant that a single `Castable` type can't be cast to a pointer of more than one type of ownership (e.g. both an `Arc` and a `Box`). We always implement a distinct type per-ownership model. Along the way crate-internal documentation for the traits and associated free-standing helper `fs`s were reworked for clarity/consistency.
Previously the helper macros in `src/lib.rs` were marked `macro_export`, making them part of the public API. Since these were meant to be crate internal, we also annotated the macros as `doc(hidden)` to avoid them appearing in the API docs. I suspect this was done before `pub(crate)` visibility was an option. This commit removes the `macro_export` and `doc(hidden)` attributes and uses a `pub(crate)` re-export to make the macros available to crate-internal users without making them part of the public API. Along the way this uncovered that the `try_mut_slice!` macro wasn't being used anywhere and so it is removed outright.
b13c99d
to
f86f39c
Compare
jsha
approved these changes
Oct 17, 2023
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 a great improvement, thanks!
Thanks for all your help along the way 🙇 |
20 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
rework CastPtr, CastConstPtr, BoxCastPtr, ArcCastPtr
This commit reworks the existing
CastPtr
,CastConstPtr
,BoxCastPtr
, andArcCastPtr
traits into a newCastable
trait with an associatedOwnership
, constrained to be a type implementing the newOwnershipMarker
trait. Three implementations of thisOwnershipMarker
trait are offered:OwnershipBox
,OwnershipArc
andOwnershipRef
.The net result is that the type system is now able to enforce our invariant that a single
Castable
type can't be cast to a pointer of more than one type of ownership (e.g. both anArc
and aBox
). ImplementingCastable
for the same type with differentOwnership
's orRustType
's will be rejected by the compiler as a conflicting trait implementation. We always implement a distinct type per-ownership model, and per rust type.Along the way crate-internal documentation for the traits and associated free-standing helper
fs
s were reworked for clarity/consistency.Resolves #349
lib: remove pub export of macros
Previously the helper macros in
src/lib.rs
were markedmacro_export
, making them part of the public API. Since these weremeant to be crate internal, we also annotated the macros as
doc(hidden)
to avoid them appearing in the API docs. I suspect this was done beforepub(crate)
visibility was an option.This commit removes the
macro_export
anddoc(hidden)
attributes and uses apub(crate)
re-export to make the macros available to crate-internal users without making them part of the public API.This also uncovered that the
try_mut_slice!
macro wasn't being used anywhere and so it is removed outright.