Return error condition from Drop impl

What if you never allowed anyone to own the object?

pub struct Object { ... }

impl Object {
    pub fn do_stuff(&mut self) { ... }
    fn finalize(self) -> Result { ... }

    pub fn with<F: FnOnce(&mut Self) -> Result>(func: F) -> Result {
        let mut object = Object { ... };
        try!(func(&mut object));
        object.finalize()
    }
}
4 Likes