#macro #derive #drop #destruct

macro destruct-drop-derive

Actual derive macro for destruct-drop

2 releases

0.1.1 Sep 28, 2021
0.1.0 Sep 28, 2021

#488 in Rust patterns

27 downloads per month
Used in 2 crates (via destruct-drop)

MIT license

77 lines


CI crates.io Documentation dependency status MIT

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


Add #[derive(DestructDrop)] to your struct or enum definition.

use destruct_drop::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();


Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)


~17K SLoC