tag | 0dcd40cbaad9ce7961fadb4acf7f69377c2c32bf | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Sat Oct 21 00:12:29 2023 -0700 |
object | 5ae57c6c80d7b49c0f4ddbde97483ec84c8dd0e7 |
frc_340821000 (10681524,com.google.android.go.tzdata5,com.google.android.tzdata5)
commit | 5ae57c6c80d7b49c0f4ddbde97483ec84c8dd0e7 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Tue Apr 11 18:00:52 2023 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Tue Apr 11 18:00:52 2023 +0000 |
tree | 63618c47b4bd4284d029fe1fcff06c0b4b6e7e00 | |
parent | 93b4878267e385254f4b328c0f909c11c892ed61 [diff] | |
parent | 9e8120416c152ac961baf2b78574239d2af2c223 [diff] |
Snap for 9912757 from 9e8120416c152ac961baf2b78574239d2af2c223 to aml-frc-release Change-Id: I86b28828d8e3b8e8a00a37e4acad02926721e934
A crate for safe and ergonomic pin-projection.
Add this to your Cargo.toml
:
[dependencies] pin-project = "1"
Compiler support: requires rustc 1.37+
#[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.
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.