#pin #macros #attribute

macro no-std pin-project-internal

An internal crate to support pin_project - do not use directly

19 releases

✓ Uses Rust 2018 edition

0.4.6 Nov 20, 2019
0.4.5 Oct 21, 2019
0.4.2 Sep 29, 2019
0.4.0-alpha.5 Aug 24, 2019

#7 in #pin

Download history 108/week @ 2019-08-07 98/week @ 2019-08-14 2333/week @ 2019-08-21 1181/week @ 2019-08-28 2570/week @ 2019-09-04 2249/week @ 2019-09-11 3761/week @ 2019-09-18 5431/week @ 2019-09-25 5688/week @ 2019-10-02 7171/week @ 2019-10-09 12094/week @ 2019-10-16 12884/week @ 2019-10-23 13470/week @ 2019-10-30 16953/week @ 2019-11-06 18069/week @ 2019-11-13

35,371 downloads per month
Used in 187 crates (1 directly)

Apache-2.0 OR MIT

81KB
1.5K SLoC

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
~20K SLoC