[][src]Attribute Macro pin_project::pinned_drop

#[pinned_drop]

An attribute for annotating an impl block that implements Drop.

This attribute is only needed when you wish to provide a Drop impl for your type. The impl block annotated with #[pinned_drop] acts just like a normal Drop impl, except for the fact that drop method takes Pin<&mut Self>. In particular, it will never be called more than once, just like Drop::drop.

Example

use pin_project::{pin_project, pinned_drop};
use std::pin::Pin;

#[pin_project(PinnedDrop)]
struct Foo {
    #[pin]
    field: u8,
}

#[pinned_drop]
impl PinnedDrop for Foo {
    fn drop(self: Pin<&mut Self>) {
        println!("Dropping: {}", self.field);
    }
}

fn main() {
    let _x = Foo { field: 50 };
}

See "pinned-drop" section of pin_project attribute for more details.