Crates.io | destruct-drop |
lib.rs | destruct-drop |
version | 0.2.0 |
source | src |
created_at | 2021-09-28 22:02:28.731095 |
updated_at | 2023-06-07 11:49:04.468449 |
description | Macro for dropping the fields of a struct or enum without dropping the container. |
homepage | |
repository | https://github.com/OpenByteDev/destruct-drop |
max_upload_size | |
id | 457803 |
size | 7,354 |
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;
#[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();
}
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)