#pin #macros #attribute

macro no-std pin-project-internal

Implementation detail of the pin-project crate

43 releases (2 stable)

new 1.0.1 Oct 15, 2020
1.0.0-alpha.1 Sep 22, 2020
0.4.27 Oct 11, 2020
0.4.23 Jul 27, 2020
0.4.6 Nov 20, 2019

#407 in Rust patterns

Download history 164454/week @ 2020-06-30 165583/week @ 2020-07-07 167166/week @ 2020-07-14 174379/week @ 2020-07-21 177731/week @ 2020-07-28 175275/week @ 2020-08-04 179751/week @ 2020-08-11 172957/week @ 2020-08-18 177891/week @ 2020-08-25 165861/week @ 2020-09-01 184294/week @ 2020-09-08 181140/week @ 2020-09-15 192638/week @ 2020-09-22 219657/week @ 2020-09-29 222066/week @ 2020-10-06 210836/week @ 2020-10-13

792,719 downloads per month
Used in 4,309 crates (2 directly)

Apache-2.0 OR MIT

95KB
1.5K SLoC

pin-project

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

A crate for safe and ergonomic pin-projection.

Usage

Add this to your Cargo.toml:

[dependencies]
pin-project = "0.4"

The current pin-project requires Rust 1.34 or later.

Examples

#[pin_project] attribute creates projection types covering all the fields of struct or enum.

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 method(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 documentation for more details, and see examples directory for more examples and generated code.

Related Projects

  • pin-project-lite: A lightweight version of pin-project written with declarative macros.

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.4–0.8MB
~21K SLoC