Is there a way to call drop
on a *mut T
that doesn't necessarily implement Drop
? I have a *mut T
that points to what I know to be a valid T
, and I would like to drop that T
(and then free the underlying memory), but I'm not guaranteed that a custom Drop
implementation exists. Thus, I'd like to do what Safe Rust would do (namely, if a Drop
implementation exists, call drop
, and then drop all of the struct fields recursively, etc), but manually. std::mem::drop
won't work because it takes a value, not a reference, so I'd have to copy the memory pointed to by my *mut T
in order to call std::mem::drop
.
This should do what you're looking for: drop_in_place in std::ptr - Rust
Perfect, thanks!