#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

#1288 in Rust patterns

Download history 39/week @ 2024-07-02 150/week @ 2024-07-09 99/week @ 2024-07-16 40/week @ 2024-07-23 71/week @ 2024-07-30 417/week @ 2024-08-06 67/week @ 2024-08-13 67/week @ 2024-08-20 108/week @ 2024-08-27 155/week @ 2024-09-03 57/week @ 2024-09-10 97/week @ 2024-09-17 166/week @ 2024-09-24 57/week @ 2024-10-01 209/week @ 2024-10-08 160/week @ 2024-10-15

624 downloads per month
Used in 5 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

~270–730KB
~17K SLoC