Skip to main content

One doc tagged with "raii"

View all tags

The Drop Trait for Custom Cleanup Logic

We've spent a lot of time exploring how Rust's ownership system manages memory. But what happens when a value goes out of scope? The compiler automatically inserts a call to a special trait: Drop. The Drop trait allows you to run custom code when a value is about to be deallocated, enabling the powerful RAII (Resource Acquisition Is Initialization) pattern that is central to safe and idiomatic Rust.