#pin #macros #attribute

no-std pin-project

A crate for safe and ergonomic pin-projection

32 releases

✓ Uses Rust 2018 edition

new 0.4.7 Jan 20, 2020
0.4.6 Nov 20, 2019
0.4.5 Oct 21, 2019
0.3.4 Jul 21, 2019
0.3.2 Mar 30, 2019

#9 in Rust patterns

Download history 6049/week @ 2019-10-04 9407/week @ 2019-10-11 12534/week @ 2019-10-18 13331/week @ 2019-10-25 15021/week @ 2019-11-01 16854/week @ 2019-11-08 19435/week @ 2019-11-15 21133/week @ 2019-11-22 26245/week @ 2019-11-29 34543/week @ 2019-12-06 34642/week @ 2019-12-13 22321/week @ 2019-12-20 21917/week @ 2019-12-27 43163/week @ 2020-01-03 47302/week @ 2020-01-10

114,632 downloads per month
Used in 519 crates (87 directly)

Apache-2.0 OR MIT

42KB
216 lines

pin-project

crates-badge docs-badge license-badge rustc-badge

A crate for safe and ergonomic pin-projection.

Documentation

Examples

Usage

Add this to your Cargo.toml:

[dependencies]
pin-project = "0.4"

The current pin-project requires Rust 1.33 or later.

Examples

pin_project attribute creates a projection struct covering all the fields.

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 foo(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 API documentation for more details.

Also, there are examples and generated code of each feature in examples directory.

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~0.5–0.8MB
~19K SLoC