Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pin-project

> 编程语言
Open source

A crate for safe and ergonomic pin-projection.

716 stars0 likes0 views
WebsiteGitHub

About

A crate for safe and ergonomic pin-projection.

pin-project

A crate for safe and ergonomic pin-projection.

Usage

Add this to your Cargo.toml:

toml
[dependencies]
pin-project = "1"

Examples

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

rust
use std::pin::Pin;

use pin_project::pin_project;

#[pin_project]
struct Struct {
    #[pin]
    pinned: T,
    unpinned: U,
}

impl Struct {
    fn method(self: Pin) {
        let this = self.project();
        let _: Pin = this.pinned; // Pinned reference to the field
        let _: &mut U = this.unpinned; // Normal reference to the field
    }
}

code like this will be generated

To use #[pin_project] on enums, you need to name the projection type returned from the method.

rust
use std::pin::Pin;

use pin_project::pin_project;

#[pin_project(project = EnumProj)]
enum Enum {
    Pinned(#[pin] T),
    Unpinned(U),
}

impl Enum {
    fn method(self: Pin) {
        match self.project() {
            EnumProj::Pinned(x) => {
                let _: Pin = x;
            }
            EnumProj::Unpinned(y) => {
                let _: &mut U = y;
            }
        }
    }
}

code like this will be generated

See #[pin_project] attribute 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 Apache License, Version 2.0 or MIT license at your option.

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.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustno-stdproc-macrorust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言