• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

examples/25-Apr-2025-947552

patches/25-Apr-2025-2016

src/25-Apr-2025-34793

tests/25-Apr-2025-11,93410,527

.cargo-checksum.jsonD25-Apr-202521.6 KiB11

Android.bpD25-Apr-2025914 3430

CHANGELOG.mdD25-Apr-202533.6 KiB779473

Cargo.lockD25-Apr-20256.1 KiB243215

Cargo.tomlD25-Apr-20251.2 KiB5950

LICENSED25-Apr-20259.9 KiB178150

LICENSE-APACHED25-Apr-20259.9 KiB178150

LICENSE-MITD25-Apr-20251,023 2421

METADATAD25-Apr-2025399 1817

MODULE_LICENSE_APACHE2D25-Apr-20250

NOTICED25-Apr-20259.9 KiB178150

README.mdD25-Apr-20253.2 KiB10677

TEST_MAPPINGD25-Apr-2025187 1110

cargo_embargo.jsonD25-Apr-2025152 109

README.md

1# pin-project
2
3[![crates.io](https://img.shields.io/crates/v/pin-project?style=flat-square&logo=rust)](https://crates.io/crates/pin-project)
4[![docs.rs](https://img.shields.io/badge/docs.rs-pin--project-blue?style=flat-square&logo=docs.rs)](https://docs.rs/pin-project)
5[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)](#license)
6[![rustc](https://img.shields.io/badge/rustc-1.56+-blue?style=flat-square&logo=rust)](https://www.rust-lang.org)
7[![build status](https://img.shields.io/github/actions/workflow/status/taiki-e/pin-project/ci.yml?branch=main&style=flat-square&logo=github)](https://github.com/taiki-e/pin-project/actions)
8
9<!-- tidy:crate-doc:start -->
10A crate for safe and ergonomic [pin-projection].
11
12## Usage
13
14Add this to your `Cargo.toml`:
15
16```toml
17[dependencies]
18pin-project = "1"
19```
20
21*Compiler support: requires rustc 1.56+*
22
23## Examples
24
25[`#[pin_project]`][`pin_project`] attribute creates projection types
26covering all the fields of struct or enum.
27
28```rust
29use std::pin::Pin;
30
31use pin_project::pin_project;
32
33#[pin_project]
34struct Struct<T, U> {
35    #[pin]
36    pinned: T,
37    unpinned: U,
38}
39
40impl<T, U> Struct<T, U> {
41    fn method(self: Pin<&mut Self>) {
42        let this = self.project();
43        let _: Pin<&mut T> = this.pinned; // Pinned reference to the field
44        let _: &mut U = this.unpinned; // Normal reference to the field
45    }
46}
47```
48
49[*code like this will be generated*][struct-default-expanded]
50
51To use `#[pin_project]` on enums, you need to name the projection type
52returned from the method.
53
54```rust
55use std::pin::Pin;
56
57use pin_project::pin_project;
58
59#[pin_project(project = EnumProj)]
60enum Enum<T, U> {
61    Pinned(#[pin] T),
62    Unpinned(U),
63}
64
65impl<T, U> Enum<T, U> {
66    fn method(self: Pin<&mut Self>) {
67        match self.project() {
68            EnumProj::Pinned(x) => {
69                let _: Pin<&mut T> = x;
70            }
71            EnumProj::Unpinned(y) => {
72                let _: &mut U = y;
73            }
74        }
75    }
76}
77```
78
79[*code like this will be generated*][enum-default-expanded]
80
81See [`#[pin_project]`][`pin_project`] attribute for more details, and
82see [examples] directory for more examples and generated code.
83
84## Related Projects
85
86- [pin-project-lite]: A lightweight version of pin-project written with declarative macros.
87
88[enum-default-expanded]: https://github.com/taiki-e/pin-project/blob/HEAD/examples/enum-default-expanded.rs
89[examples]: https://github.com/taiki-e/pin-project/blob/HEAD/examples/README.md
90[pin-project-lite]: https://github.com/taiki-e/pin-project-lite
91[pin-projection]: https://doc.rust-lang.org/std/pin/index.html#projections-and-structural-pinning
92[struct-default-expanded]: https://github.com/taiki-e/pin-project/blob/HEAD/examples/struct-default-expanded.rs
93
94<!-- tidy:crate-doc:end -->
95
96[`pin_project`]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html
97
98## License
99
100Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
101[MIT license](LICENSE-MIT) at your option.
102
103Unless you explicitly state otherwise, any contribution intentionally submitted
104for inclusion in the work by you, as defined in the Apache-2.0 license, shall
105be dual licensed as above, without any additional terms or conditions.
106