#drop #macro-derive #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

#1481 in Rust patterns

Download history 19/week @ 2024-01-22 334/week @ 2024-01-29 7/week @ 2024-02-05 18/week @ 2024-02-12 25/week @ 2024-02-19 50/week @ 2024-02-26 80/week @ 2024-03-04 123/week @ 2024-03-11 62/week @ 2024-03-18 47/week @ 2024-03-25 106/week @ 2024-04-01 56/week @ 2024-04-08 142/week @ 2024-04-15 40/week @ 2024-04-22 87/week @ 2024-04-29

344 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

~325–780KB
~19K SLoC