tag | e5db4d32d8f66c5b36d2499d1b23912dfa682674 | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Tue May 07 10:55:49 2024 -0700 |
object | 25dc0f43f86e35f4a672a979872adab09a4073b5 |
Android 14.0.0 release 34
commit | 25dc0f43f86e35f4a672a979872adab09a4073b5 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Nov 16 00:13:39 2023 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Nov 16 00:13:39 2023 +0000 |
tree | 570f6d6a8e622c88b6332edf44fa702561b2af53 | |
parent | 8014df694c6c591694dd9e0706ce7c100f654f21 [diff] | |
parent | 4052a3c23a002a7fa935ed3df487fe97d954b0f6 [diff] |
Snap for 11104212 from 4052a3c23a002a7fa935ed3df487fe97d954b0f6 to 24Q1-release Change-Id: I2a7d516bd8bbb4e341e51a189840e6f959c2b85d
A crate for safe and ergonomic pin-projection.
Add this to your Cargo.toml
:
[dependencies] pin-project = "1"
Compiler support: requires rustc 1.56+
#[pin_project]
attribute creates projection types covering all the fields of struct or enum.
use std::pin::Pin; use pin_project::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 } }
code like this will be generated
To use #[pin_project]
on enums, you need to name the projection type returned from the method.
use std::pin::Pin; use pin_project::pin_project; #[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 #[pin_project]
attribute for more details, and see examples directory for more examples and generated code.
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.