Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate nodrop; // 0.1.12
- use nodrop::NoDrop;
- use std::ops::Drop;
- struct Precious;
- fn cleanup(_: Precious) { println!("cleaned up"); }
- struct Abc(NoDrop<Precious>);
- struct AbcDroppable(Option<Precious>);
- impl Abc {
- fn make_droppable(self) -> AbcDroppable {
- AbcDroppable(Some(self.0.into_inner()))
- }
- }
- impl Drop for AbcDroppable {
- fn drop(&mut self) {
- cleanup(self.0.take().unwrap()) // Should abort or something? Do we want to panic in drop?
- }
- }
- fn main() {
- let abc = Abc(NoDrop::new(Precious)); // init our struct.
- abc.make_droppable();
- }
Add Comment
Please, Sign In to add comment