Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

destructor

The clean-up code that runs when a value is dropped.

A destructor is a type's Drop implementation; a type with one can never be Copy (E0184).

Examples

  • impl Drop for Noisy { fn drop(&mut self) { println!("bye"); } } prints bye when a Noisy goes out of scope.

  • Adding #[derive(Clone, Copy)] to a type that implements Drop fails with E0184.

Read the full section →