tag | d29acf97a2e56d4405d89cf9a7af824c8dd21fc5 | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Fri Sep 17 01:20:01 2021 -0700 |
object | c13bfaddc9740b4187daee2b20dfafd0efb453ff |
Platform Tools Release 31.0.3 (7562133)
commit | c13bfaddc9740b4187daee2b20dfafd0efb453ff | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Jun 24 04:45:53 2021 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Jun 24 04:45:53 2021 +0000 |
tree | a2808291a9d00789d7f23e0e6bc9e133aace307a | |
parent | d558cab737553c29a9dac757e9bc66123298228d [diff] | |
parent | b845c5fd84f50f28cd5cce350eac405562744e3b [diff] |
Snap for 7487883 from b845c5fd84f50f28cd5cce350eac405562744e3b to sdk-release Change-Id: Ib13e87d7e64db9dab9508496b369a8b73616f2a0
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.