A lightweight version of pin-project written with declarative macros.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-05-04 17:07:32 +09:00
.github ci,tools: Update config and script 2026-05-04 17:07:24 +09:00
src Fix comment 2026-04-16 00:00:09 +09:00
tests tests: Update lint test 2026-05-04 17:07:32 +09:00
tools ci,tools: Update config and script 2026-05-04 17:07:24 +09:00
.clippy.toml Apply deprecated_safe lint 2024-08-25 21:59:25 +09:00
.cspell.json tools: Update tidy.sh and related configs/markers 2025-02-03 06:21:02 +09:00
.deny.toml Update .deny.toml 2026-01-11 19:18:08 +09:00
.editorconfig tools: Update tidy.sh and related configs/markers 2025-02-03 06:21:02 +09:00
.git-blame-ignore-revs Add .git-blame-ignore-revs 2025-02-05 15:33:22 +09:00
.gitattributes gitattributes: Disable linguist detection for tools/tidy.sh 2025-02-05 15:56:26 +09:00
.gitignore Update script and CI config 2026-03-13 02:47:15 +09:00
.markdownlint-cli2.yaml Update comments 2025-02-08 15:22:46 +09:00
.rustfmt.toml rustfmt: Set hex_literal_case = "Upper" 2026-01-06 23:27:34 +09:00
.shellcheckrc Apply zizmor and update scripts 2025-12-05 01:53:36 +09:00
.taplo.toml tidy: Check TOML format 2024-02-23 03:10:03 +09:00
Cargo.toml Release 0.2.17 2026-02-27 15:18:59 +00:00
CHANGELOG.md Release 0.2.17 2026-02-27 15:18:59 +00:00
DEVELOPMENT.md mv tests/README.md DEVELOPMENT.md 2022-12-24 15:43:13 +09:00
LICENSE-APACHE Remove appendix from LICENCE-APACHE 2020-09-10 20:11:43 +09:00
LICENSE-MIT Initial commit 2019-10-23 00:28:55 +09:00
README.md tools: Update tidy.sh and related configs/markers 2025-02-03 06:21:02 +09:00

pin-project-lite

crates.io docs.rs license msrv github actions

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

Usage

Add this to your Cargo.toml:

[dependencies]
pin-project-lite = "0.2"

Examples

pin_project! macro creates a projection type covering all the fields of struct.

use std::pin::Pin;

use pin_project_lite::pin_project;

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
    }
}

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

use std::pin::Pin;

use pin_project_lite::pin_project;

pin_project! {
    #[project = EnumProj]
    enum Enum<T, U> {
        Variant { #[pin] pinned: T, unpinned: U },
    }
}

impl<T, U> Enum<T, U> {
    fn method(self: Pin<&mut Self>) {
        match self.project() {
            EnumProj::Variant { pinned, unpinned } => {
                let _: Pin<&mut T> = pinned;
                let _: &mut U = unpinned;
            }
        }
    }
}

pin-project vs pin-project-lite

Here are some similarities and differences compared to pin-project.

Similar: Safety

pin-project-lite guarantees safety in much the same way as pin-project. Both are completely safe unless you write other unsafe code.

Different: Minimal design

This library does not tackle as expansive of a range of use cases as pin-project does. If your use case is not already covered, please use pin-project.

This is the only reason to use this crate. However, if you already have proc-macro related dependencies in your crate's dependency graph, there is no benefit from using this crate. (Note: There is almost no difference in the amount of code generated between pin-project and pin-project-lite.)

Different: No useful error messages

This macro does not handle any invalid input. So error messages are not to be useful in most cases. If you do need useful error messages, then upon error you can pass the same input to pin-project to receive a helpful description of the compile error.

Different: No support for custom Unpin implementation

pin-project supports this by UnsafeUnpin. (!Unpin is supported by both pin-project and pin-project-lite.)

Different: No support for tuple structs and tuple variants

pin-project supports this.

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.