Bug: 156526402

Clone this repo:
  1. a38084e Update TEST_MAPPING by Jeff Vander Stoep · 10 days ago master
  2. 926348b Upgrade pin-project to 1.0.12 by Jeff Vander Stoep · 8 weeks ago main-16k-with-phones
  3. 23166d6 Update pin-project to 1.0.10 am: 8915193b0d am: ac81d17ea0 am: 365fe11dc7 by David LeGare · 11 months ago android13-dev android13-mainline-go-adservices-release android13-mainline-go-odp-release android13-qpr1-release android13-qpr1-s1-release android13-qpr1-s2-release android13-qpr1-s3-release android13-qpr1-s4-release android13-qpr1-s5-release android13-qpr1-s6-release android13-qpr1-s7-release android13-qpr1-s8-release main-16k aml_go_ads_330913000 aml_go_odp_330912000 android-13.0.0_r16 android-13.0.0_r17 android-13.0.0_r18 android-13.0.0_r19 android-13.0.0_r20 android-13.0.0_r21 android-13.0.0_r22 android-13.0.0_r23 android-13.0.0_r24 android-13.0.0_r27 android-13.0.0_r28 android-13.0.0_r29 android-13.0.0_r30 t_frc_ase_330444010 t_frc_odp_330442000
  4. 365fe11 Update pin-project to 1.0.10 am: 8915193b0d am: ac81d17ea0 by David LeGare · 11 months ago
  5. ac81d17 Update pin-project to 1.0.10 am: 8915193b0d by David LeGare · 11 months ago


crates.io docs.rs license rustc build status

A crate for safe and ergonomic pin-projection.


Add this to your Cargo.toml:

pin-project = "1"

Compiler support: requires rustc 1.37+


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

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

struct Struct<T, U> {
    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

To use #[pin_project] on enums, you need to name the projection type returned from the method.

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

#[pin_project(project = EnumProj)]
enum Enum<T, U> {
    Pinned(#[pin] T),

impl<T, U> Enum<T, U> {
    fn method(self: Pin<&mut Self>) {
        match self.project() {
            EnumProj::Pinned(x) => {
                let _: Pin<&mut T> = x;
            EnumProj::Unpinned(y) => {
                let _: &mut U = y;

code like this will be generated

See documentation for more details, and see examples directory for more examples and generated code.

Related Projects

  • pin-project-lite: A lightweight version of pin-project written with declarative macros.


Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.