I have the code:
struct Foo {}
impl Default for Foo {
fn default() -> Self {
Self {}
}
}
impl Drop for Foo {
fn drop(&mut self) {
// Do something
}
}
fn main() {
{
let foo = Some(Foo::default());
let foo = None; // Would this line trigger `Foo::drop`?
};
{
let mut foo = Some(Foo::default());
foo = None; // Would this line trigger `Foo::drop`?
};
}
Are the resources occupied by foo
s released properly?
The first situation (variable overwritten) will not trigger drop
, so I added the second situation, in which I'm also confused.