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). Implementing Castable for the same type with different Ownership's or RustType'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 fss were reworked for clarity/consistency.
Resolves #349
lib: remove pub export of macros
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.
This also uncovered that the try_mut_slice! macro wasn't being used anywhere and so it is removed outright.
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 were meant to be crate internal, we also annotated the macros asdoc(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.