We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I had just fun: Type erased pointers that Drop properly:
pub struct FatErasedPtr { ptr: ErasedPtr, dropfn: fn(ErasedPtr), } impl<P: ErasablePtr + 'static> From<P> for FatErasedPtr { #[inline(always)] fn from(this: P) -> Self { fn dropfn<P: ErasablePtr> (this: ErasedPtr) { unsafe { <P as ErasablePtr>::unerase(this) }; } FatErasedPtr { ptr: P::erase(this), dropfn: dropfn::<P>, } } } impl Drop for FatErasedPtr { fn drop(&mut self) { (self.dropfn)(self.ptr) } } #[test] fn faterasedptr() { use alloc::rc::Rc; let rc: Rc<i32> = Rc::new(123); let fat_erased: FatErasedPtr = FatErasedPtr::from(rc); assert_eq!(core::mem::size_of_val(&fat_erased), core::mem::size_of::<usize>()*2); }
Was just a curious experiment here. I can complete that and send a PR if this is interesting.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I had just fun: Type erased pointers that Drop properly:
Was just a curious experiment here. I can complete that and send a PR if this is interesting.
The text was updated successfully, but these errors were encountered: