Tutorial by Examples

use std::ops::Drop; struct Foo(usize); impl Drop for Foo { fn drop(&mut self) { println!("I had a {}", self.0); } }
use std::ops::Drop; #[derive(Debug)] struct Bar(i32); impl Bar { fn get<'a>(&'a mut self) -> Foo<'a> { let temp = self.0; // Since we will also capture `self` we.. // ..will have to copy the value out first Foo(self, temp) ...
Run-time memory management with Rc can be very useful, but it can also be difficult to wrap one's head around, especially if your code is very complex and a single instance is referenced by tens or even hundreds of other types in many scopes. Writing a Drop trait that includes println!("Droppi...

Page 1 of 1