#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

#1419 in Rust patterns

Download history 20/week @ 2023-12-22 15/week @ 2023-12-29 13/week @ 2024-01-05 37/week @ 2024-01-12 4/week @ 2024-01-19 29/week @ 2024-01-26 324/week @ 2024-02-02 14/week @ 2024-02-09 23/week @ 2024-02-16 39/week @ 2024-02-23 69/week @ 2024-03-01 110/week @ 2024-03-08 73/week @ 2024-03-15 61/week @ 2024-03-22 87/week @ 2024-03-29 58/week @ 2024-04-05

301 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

~295–740KB
~18K SLoC