must_destroy 0.3.1

simple forced explcit destructors
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented0 out of 6 items with examples
  • Size
  • Source code size: 6.71 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.4 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sekhat/must_destroy
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sekhat

must_destroy

Must destroy is used to create a paramterized destructor for a type that must be explicitly called.

MustDestroy<T, Args> acts as a guard for a wrapped type that implements the Destroy trait, that causes a panic if the guard is dropped.

However, calling destroy upon the guard, will call destroy on wrapped child, and will be consumed safely.

use must_destroy::{MustDestroy, Destroy};
    struct MyDestroyableItem;

    impl Destroy<(&'_ str, i32)> for MyDestroyableItem {
        fn destroy(self, args: (&str, i32)) {
            
            // Do things to destroy item...

            // Just to show our arguments got through fine
            assert_eq!("Test String", args.0);
            assert_eq!(12, args.1);
        }
    }

    fn main() {
        let destroy_me = MustDestroy::new(MyDestroyableItem);

        // Dropping the item here would cause a panic at runtime
        // drop(destroy_me)

        // However calling destroy will consume the item, and not cause
        // a panic.
        
        // We currently have to pass the arguments as a tuple.
        //
        // I'd like to be able to hide the need to do this though.
        destroy_me.destroy(("Test String", 12));
    }