#derive #drop #macro-derive #macro #destruct

destruct-drop

Macro for dropping the fields of a struct or enum without dropping the container

2 unstable releases

0.2.0 Jun 7, 2023
0.1.0 Sep 28, 2021

#1408 in Rust patterns

Download history 51/week @ 2024-07-20 54/week @ 2024-07-27 191/week @ 2024-08-03 300/week @ 2024-08-10 74/week @ 2024-08-17 95/week @ 2024-08-24 163/week @ 2024-08-31 56/week @ 2024-09-07 71/week @ 2024-09-14 184/week @ 2024-09-21 69/week @ 2024-09-28 85/week @ 2024-10-05 271/week @ 2024-10-12 207/week @ 2024-10-19 153/week @ 2024-10-26 249/week @ 2024-11-02

904 downloads per month
Used in 6 crates (via netcorehost)

MIT license

5KB

destruct-drop

CI crates.io Documentation dependency status MIT

Macro for dropping the fields of a struct or enum without dropping the container.

Usage

Add #[derive(DestructDrop)] to your struct or enum definition.

use destruct_drop::DestructDrop;

#[derive(DestructDrop)]
struct Container {
    inner: Inner
}

struct Inner;

impl Drop for Container {
    fn drop(&mut self) {
        println!("dropped Container");
    }
}

impl Drop for Inner {
    fn drop(&mut self) {
        println!("dropped Inner");
    }
}

fn main() {
    // prints "dropped Inner" and then "dropped Container"
    drop(Container { inner: Inner });

    // prints only "dropped Inner"
    Container { inner: Inner }.destruct_drop();
}

License

Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Dependencies

~220–660KB
~16K SLoC