dispose 0.1.0

A simple wrapper for values that must be consumed on drop.
Documentation

A small crate for handling resources that must be consumed at the end of their lifetime.

Since Rust's type system is affine rather than linear, Drop::drop mutably borrows self, rather than consuming it. For the most part, this is fine, but for some cases (such as working with the crate gfx_hal) resources must be consumed on drop. This crate and the dispose_derive crate serve to cover the typical boilerplate for such cases by managing the ManuallyDrop wrapper for you.

As a bonus, this crate makes it easy to defer the execution of an FnOnce closure to the end of a scope, which can be done using the defer function.

Examples

use dispose::{Dispose, Disposable};

struct MyStruct;

impl Dispose for MyStruct {
fn dispose(self) { println!("Goodbye, world!"); }
}

{
let _my_struct = Disposable::new(MyStruct);
} // prints "Goodbye, world!"