Skip to content
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

RFC: Feature/newtype #83

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

RFC: Feature/newtype #83

wants to merge 7 commits into from

Conversation

cehteh
Copy link

@cehteh cehteh commented Feb 2, 2023

I anticipate the change from the type alias to a newtype implementation here. Maybe this qualifies/requires a major version bump (I suspect this is still binary compatible as its a transparent repr).

A possible alternative would be to implement 'with()/with_mut()' functions as toplevel crate functions (I wont necessary like that, but ymmv). Keeping them in the Erasable trait won't be totally bad as well.

This allows one to use ErasedPtr where rust won't allow a typed reference. For example in
recursive types.
* remove references of the unerased value
* fix memory leaks in tests by unerase/drop the erased values
 - using scopeguard to write the pointer back into its original place
 - correct the ManuallyDrop() to wrap the actual value and take it out in the scopeguard
This changes ErasedPtr from type alias to a newtype implementation.

Thus ErasedPtr implements few methods now:

 * `as_unit_ptr(&self) -> *const ()` getting the pointer value for diagnostics.
 * `with(FnOnce(&E)-> T)` and `with_mut(FnOnce(&E)-> T)` are moved from the Eraseable trait to
   ErasedPtr.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant