All Projects → taiki-e → Pin Project

taiki-e / Pin Project

Licence: other
A crate for safe and ergonomic pin-projection.

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to Pin Project

Drone Core
The core crate for Drone, an Embedded Operating System.
Stars: ✭ 263 (+51.15%)
Mutual labels:  no-std
Serde
Serialization framework for Rust
Stars: ✭ 4,901 (+2716.67%)
Mutual labels:  no-std
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-74.71%)
Mutual labels:  no-std
Rubble
(going to be a) BLE stack for embedded Rust
Stars: ✭ 292 (+67.82%)
Mutual labels:  no-std
Cortex M Quickstart
Template to develop bare metal applications for Cortex-M microcontrollers
Stars: ✭ 372 (+113.79%)
Mutual labels:  no-std
Cortex M Rtic
Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers
Stars: ✭ 623 (+258.05%)
Mutual labels:  no-std
liar
Flexible, stand-alone benchmarking
Stars: ✭ 16 (-90.8%)
Mutual labels:  no-std
Drone
CLI utility for Drone, an Embedded Operating System.
Stars: ✭ 114 (-34.48%)
Mutual labels:  no-std
Cortex M
Low level access to Cortex-M processors
Stars: ✭ 379 (+117.82%)
Mutual labels:  no-std
Rhai
Rhai - An embedded scripting language for Rust.
Stars: ✭ 958 (+450.57%)
Mutual labels:  no-std
Embedded Graphics
A no_std graphics library for embedded applications
Stars: ✭ 293 (+68.39%)
Mutual labels:  no-std
Time
Simple time handling in Rust
Stars: ✭ 334 (+91.95%)
Mutual labels:  no-std
Xargo
The sysroot manager that lets you build and customize `std`
Stars: ✭ 841 (+383.33%)
Mutual labels:  no-std
Cortex M Rt
Minimal startup / runtime for Cortex-M microcontrollers
Stars: ✭ 286 (+64.37%)
Mutual labels:  no-std
Bitmatch
A Rust crate that allows you to match, bind, and pack the individual bits of integers.
Stars: ✭ 82 (-52.87%)
Mutual labels:  no-std
littlefs2
Idiomatic Rust API for littlefs
Stars: ✭ 19 (-89.08%)
Mutual labels:  no-std
Heapless
Heapless, `static` friendly data structures
Stars: ✭ 575 (+230.46%)
Mutual labels:  no-std
Utest
Unit `#[test]`ing for microcontrollers and other `no_std` systems
Stars: ✭ 119 (-31.61%)
Mutual labels:  no-std
Governor
A rate-limiting library for Rust (formerly ratelimit_meter)
Stars: ✭ 99 (-43.1%)
Mutual labels:  no-std
Byte
A low-level, zero-copy, panic-free, binary serializer and deserializer. (parser and encoder)
Stars: ✭ 29 (-83.33%)
Mutual labels:  no-std

pin-project

crates.io docs.rs license rustc build status

A crate for safe and ergonomic pin-projection.

Usage

Add this to your Cargo.toml:

[dependencies]
pin-project = "1"

Compiler support: requires rustc 1.37+

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

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

use pin_project::pin_project;
use std::pin::Pin;

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

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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].