rustls / rustls-ffi

Use Rustls from any language
Other
124 stars 31 forks source link

rework `CastPtr`, `CastConstPtr`, `BoxCastPtr`, `ArcCastPtr` #353

Closed cpu closed 8 months ago

cpu commented 9 months ago

rework CastPtr, CastConstPtr, BoxCastPtr, ArcCastPtr

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.

jsha commented 9 months ago

I like Castable a lot!

cpu commented 8 months ago

Thanks for all your help along the way :bow: