1 | use pin_utils::{unsafe_pinned, unsafe_unpinned, pin_mut}; |
2 | use std::pin::Pin; |
3 | use std::marker::Unpin; |
4 | |
5 | struct Foo<T1, T2> { |
6 | field1: T1, |
7 | field2: T2, |
8 | } |
9 | |
10 | impl<T1, T2> Foo<T1, T2> { |
11 | unsafe_pinned!(field1: T1); |
12 | unsafe_unpinned!(field2: T2); |
13 | } |
14 | |
15 | impl<T1: Unpin, T2> Unpin for Foo<T1, T2> {} // Conditional Unpin impl |
16 | |
17 | #[test] |
18 | fn projection() { |
19 | let foo = Foo { field1: 1, field2: 2 }; |
20 | pin_mut!(foo); |
21 | |
22 | let x1: Pin<&mut i32> = foo.as_mut().field1(); |
23 | assert_eq!(*x1, 1); |
24 | |
25 | let x2: &mut i32 = foo.as_mut().field2(); |
26 | assert_eq!(*x2, 2); |
27 | } |
28 | |