destruct-drop-derive

Crates.iodestruct-drop-derive
lib.rsdestruct-drop-derive
version0.2.0
sourcesrc
created_at2021-09-28 21:57:18.787602
updated_at2023-06-07 11:48:52.308096
descriptionActual derive macro for destruct-drop.
homepage
repositoryhttps://github.com/OpenByteDev/destruct-drop-derive
max_upload_size
id457800
size6,327
OpenByte (OpenByteDev)

documentation

https://docs.rs/destruct-drop-derive

README

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)

Commit count: 0

cargo fmt