I need to run an action when the item is dropped by implementing drop but I am not sure if I implement drop myself how to actually drop the value.
I plan to create a wrapper such as
use crate::User;
struct MyDroppableUser(pub User);
impl Drop for MyDroppableUser{
//...
}
I want to reset all subscriptions of users when MyDroppableUser goes out of context.
So how can I implement drop without creating dangling pointers?
oh, that makes much more sense I thought if a custom destructor is provided that is run leaving cleaning up memory to implementer "or" it is run by default as default drop implementation
In general, Rust is designed with the principle of least surprise in mind, i.e., you can generally expect that the default behavior of some language feature is the right thing to do, and that you don't have to actively prevent yourself from shooting yourself in the foot. Of course no language is perfect, and there may be exceptions and perhaps non-obvious details, but memory management is a core value in Rust, so it is probably the most well-fleshed-out aspect of the language.