#pin #macros #attribute

pin-project

A crate for safe and ergonomic pin-projection

20 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

new 0.4.0-alpha.4 Aug 23, 2019
0.3.5 Aug 14, 2019
0.3.4 Jul 21, 2019
0.3.2 Mar 30, 2019

#48 in Rust patterns

Download history 107/week @ 2019-05-10 182/week @ 2019-05-17 39/week @ 2019-05-24 57/week @ 2019-05-31 41/week @ 2019-06-07 44/week @ 2019-06-14 224/week @ 2019-06-21 99/week @ 2019-06-28 194/week @ 2019-07-05 226/week @ 2019-07-12 217/week @ 2019-07-19 294/week @ 2019-07-26 384/week @ 2019-08-02 566/week @ 2019-08-09 616/week @ 2019-08-16

1,015 downloads per month
Used in 5 crates (4 directly)

Apache-2.0/MIT

19KB

pin-project

Build Status Crates.io Docs.rs License Minimum supported Rust version

A crate for safe and ergonomic pin-projection.

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
pin-project = "0.4.0-alpha.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 Foo<T, U> {
    #[pin]
    future: T,
    field: U,
}

impl<T, U> Foo<T, U> {
    fn baz(mut self: Pin<&mut Self>) {
        let this = self.project();
        let _: Pin<&mut T> = this.future; // Pinned reference to the field
        let _: &mut U = this.field; // Normal reference to the field
    }
}

Code like this will be generated

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

~1MB
~22K SLoC