-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Run destructors when clearing PinVec #21
Conversation
Also adds a Drop impl for PinVec, and removes the Drop impl for PinSlab since PinSlab's Drop is redundant now. Fixes udoprog#20
You can merge as-is or you can apply the suggestion. Your choice! |
Thanks for adding me to the repo! I'll go ahead and merge this with the change you mentioned. Please take a look though and I'm happy to make additional changes if needed. |
// will not be accessed again. | ||
unsafe { drop_in_place(self.get_mut(i).unwrap()) } | ||
if mem::needs_drop::<T>() { | ||
let (last_slot, offset, _) = calculate_key(self.len()); |
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.
Oh, this is really neat!
// Safety: we initialized slice to only point to the already-initialized elements. | ||
// It's safe to drop_in_place because we are draining the Vec. | ||
unsafe { | ||
let slice: &mut [T] = mem::transmute(slice); |
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.
I think I'm partial to casting to a pointer above and reconstituting it as a slice over transmuting a slice. But both are equally correct to me so I don't mind it.
Here's that version:
let len = if i < last_slot { slot.len() } else { offset };
drop_in_place(from_raw_parts_mut(slot.as_mut_ptr() as *mut T, len));
Also adds a
Drop
impl forPinVec
, and removes theDrop
impl forPinSlab
sincePinSlab
'sDrop
is redundant now.Fixes #20, and also includes the test from #19.