Skip to content

Macro for dropping the fields of a struct or enum without dropping the container.

License

Notifications You must be signed in to change notification settings

OpenByteDev/destruct-drop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Macro for dropping the fields of a struct or enum without dropping the container.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages