> It *is* possible to forbid Drop in Rust for a type and require explicit destruction
Do you mind giving an example of how it can be done? I've been looking for a way to do this some time ago, but haven't really found anything.
Top-level
> It *is* possible to forbid Drop in Rust for a type and require explicit destruction Do you mind giving an example of how it can be done? I've been looking for a way to do this some time ago, but haven't really found anything. 5 comments
@iliazeus @lina Does `std::mem::ManuallyDrop` do this? Or do you mean forbid it at the type level? |
@iliazeus @lina personally, I approach this by having an explicit destroy function, which consumes the value, and then jamming an assert into the drop path which checks whether you're actually inside the explicit destroy function. You still end up with the unfortunate stuff around std::mem::forget, but in those cases I make sure it's merely a leak rather than a safety violation.