[][src]Crate pin_project

A crate for safe and ergonomic pin-projection.

Examples

#[pin_project] attribute creates projection types covering all the fields of struct or enum.

use pin_project::pin_project;
use std::pin::Pin;

#[pin_project]
struct Struct<T, U> {
    #[pin]
    pinned: T,
    unpinned: U,
}

impl<T, U> Struct<T, U> {
    fn method(self: Pin<&mut Self>) {
        let this = self.project();
        let _: Pin<&mut T> = this.pinned; // Pinned reference to the field
        let _: &mut U = this.unpinned; // Normal reference to the field
    }
}

code like this will be generated

See #[pin_project] attribute for more details, and see examples directory for more examples and generated code.

Traits

UnsafeUnpin

A trait used for custom implementations of Unpin. This trait is used in conjunction with the UnsafeUnpin argument to #[pin_project]

Attribute Macros

pin_project

An attribute that creates projection types covering all the fields of struct or enum.

pinned_drop

An attribute for annotating an impl block that implements Drop.

project

An attribute to provide way to refer to the projected type returned by project method.

project_ref

An attribute to provide way to refer to the projected type returned by project_ref method.

project_replace

An attribute to provide way to refer to the projected type returned by project_replace method.