When a value goes out of scope, Rust runs its Drop impl — no finally, no defer, no close() you can forget. That is RAII: acquiring the resource is constructing the value, and releasing it is the value ending.
struct Guard(&'static str);
impl Drop for Guard {
fn drop(&mut self) {
println!("release {}", self.0);
}
}
You never call drop yourself. std::mem::drop(value) exists, but all it does is take ownership and let the value fall out of scope early.
