Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustDrop plus move interactionSingle-choice MCQ

Why can't you move a field out of a struct that implements `Drop`, as in the snippet below, and what is the underlying mechanism?

struct Guard { name: String } impl Drop for Guard { fn drop(&mut self) { println!("dropping {}", self.name); } } fn take(g: Guard) -> String { g.name // error[E0509]: cannot move out of type `Guard`, which implements `Drop` }