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

macro destruct-drop-derive

Actual derive macro for destruct-drop

3 unstable releases

0.2.0 Jun 7, 2023
0.1.1 Sep 28, 2021
0.1.0 Sep 28, 2021

#7 in #destruct

Download history 39/week @ 2024-07-22 78/week @ 2024-07-29 425/week @ 2024-08-05 65/week @ 2024-08-12 73/week @ 2024-08-19 110/week @ 2024-08-26 160/week @ 2024-09-02 58/week @ 2024-09-09 72/week @ 2024-09-16 181/week @ 2024-09-23 61/week @ 2024-09-30 168/week @ 2024-10-07 201/week @ 2024-10-14 210/week @ 2024-10-21 155/week @ 2024-10-28 249/week @ 2024-11-04

895 downloads per month
Used in 7 crates (via destruct-drop)

MIT license

7KB
77 lines

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

~235–680KB
~16K SLoC