// Non-copyable types. struct Empty; struct Null; // A trait generic over `T`. trait DoubleDrop { // Define a method on the caller type which takes an // additional single parameter `T` and does nothing with it. fn double_drop(self, _: T); } // Implement `DoubleDrop` for any generic parameter `T` and // caller `U`. impl DoubleDrop for U { // This method takes ownership of both passed arguments, // deallocating both. fn double_drop(self, _: T) { std::hint::black_box(true); } } fn main() { let empty = Empty; let null = Null; // Deallocate `empty` and `null`. empty.double_drop(null); Null.double_drop(Empty); }