Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
examples/ | 03-May-2024 | - | 946 | 549 | ||
patches/ | 03-May-2024 | - | 15 | 12 | ||
src/ | 03-May-2024 | - | 569 | 331 | ||
tests/ | 03-May-2024 | - | 11,309 | 9,976 | ||
.cargo_vcs_info.json | D | 03-May-2024 | 74 | 6 | 5 | |
.gitignore | D | 03-May-2024 | 272 | 7 | 5 | |
Android.bp | D | 03-May-2024 | 2 KiB | 59 | 54 | |
CHANGELOG.md | D | 03-May-2024 | 26.9 KiB | 658 | 406 | |
Cargo.toml | D | 03-May-2024 | 1.3 KiB | 41 | 36 | |
Cargo.toml.orig | D | 03-May-2024 | 942 | 38 | 33 | |
LICENSE | D | 03-May-2024 | 9.9 KiB | 178 | 150 | |
LICENSE-APACHE | D | 03-May-2024 | 9.9 KiB | 178 | 150 | |
LICENSE-MIT | D | 03-May-2024 | 1,023 | 24 | 21 | |
METADATA | D | 03-May-2024 | 397 | 20 | 19 | |
MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | |||
NOTICE | D | 03-May-2024 | 9.9 KiB | 178 | 150 | |
OWNERS | D | 03-May-2024 | 40 | 2 | 1 | |
README.md | D | 03-May-2024 | 3 KiB | 101 | 75 | |
TEST_MAPPING | D | 03-May-2024 | 161 | 9 | 8 | |
cargo2android.json | D | 03-May-2024 | 142 | 9 | 9 |
README.md
1# pin-project 2 3[](https://crates.io/crates/pin-project) 4[](https://docs.rs/pin-project) 5[](#license) 6[](https://www.rust-lang.org) 7[](https://github.com/taiki-e/pin-project/actions) 8 9A crate for safe and ergonomic [pin-projection]. 10 11## Usage 12 13Add this to your `Cargo.toml`: 14 15```toml 16[dependencies] 17pin-project = "1" 18``` 19 20*Compiler support: requires rustc 1.37+* 21 22## Examples 23 24[`#[pin_project]`][`pin_project`] attribute creates projection types 25covering all the fields of struct or enum. 26 27```rust 28use pin_project::pin_project; 29use std::pin::Pin; 30 31#[pin_project] 32struct Struct<T, U> { 33 #[pin] 34 pinned: T, 35 unpinned: U, 36} 37 38impl<T, U> Struct<T, U> { 39 fn method(self: Pin<&mut Self>) { 40 let this = self.project(); 41 let _: Pin<&mut T> = this.pinned; // Pinned reference to the field 42 let _: &mut U = this.unpinned; // Normal reference to the field 43 } 44} 45``` 46 47[*code like this will be generated*][struct-default-expanded] 48 49To use `#[pin_project]` on enums, you need to name the projection type 50returned from the method. 51 52```rust 53use pin_project::pin_project; 54use std::pin::Pin; 55 56#[pin_project(project = EnumProj)] 57enum Enum<T, U> { 58 Pinned(#[pin] T), 59 Unpinned(U), 60} 61 62impl<T, U> Enum<T, U> { 63 fn method(self: Pin<&mut Self>) { 64 match self.project() { 65 EnumProj::Pinned(x) => { 66 let _: Pin<&mut T> = x; 67 } 68 EnumProj::Unpinned(y) => { 69 let _: &mut U = y; 70 } 71 } 72 } 73} 74``` 75 76[*code like this will be generated*][enum-default-expanded] 77 78See [documentation](https://docs.rs/pin-project) for more details, and 79see [examples] directory for more examples and generated code. 80 81[`pin_project`]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html 82[enum-default-expanded]: examples/enum-default-expanded.rs 83[examples]: examples/README.md 84[pin-projection]: https://doc.rust-lang.org/std/pin/index.html#projections-and-structural-pinning 85[struct-default-expanded]: examples/struct-default-expanded.rs 86 87## Related Projects 88 89- [pin-project-lite]: A lightweight version of pin-project written with declarative macros. 90 91[pin-project-lite]: https://github.com/taiki-e/pin-project-lite 92 93## License 94 95Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or 96[MIT license](LICENSE-MIT) at your option. 97 98Unless you explicitly state otherwise, any contribution intentionally submitted 99for inclusion in the work by you, as defined in the Apache-2.0 license, shall 100be dual licensed as above, without any additional terms or conditions. 101