[][src]Crate pin_project

A crate for safe and ergonomic pin-projection.

This crate provides the following attribute macros:

  • pin_project - An attribute that creates a projection struct covering all the fields.
  • pinned_drop - An attribute for annotating a function that implements Drop.
  • project - An attribute to support pattern matching.


pin_project attribute creates a projection struct covering all the fields.

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

struct Struct<T, U> {
    pinned: T,
    unpinned: U,

impl<T, U> Struct<T, U> {
    fn foo(mut 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

There are examples and generated code of each feature in examples directory.



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