This repository was archived by the owner on May 23, 2024. It is now read-only.
File tree 2 files changed +66
-0
lines changed
2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: marker:: PhantomData ;
2
+
3
+ #[ derive( Default ) ]
4
+ struct MyType < ' a > {
5
+ field : usize ,
6
+ _phantom : PhantomData < & ' a ( ) > ,
7
+ }
8
+
9
+ #[ derive( Default ) ]
10
+ struct MyTypeVariant < ' a > {
11
+ field : usize ,
12
+ _phantom : PhantomData < & ' a ( ) > ,
13
+ }
14
+
15
+ trait AsVariantTrait {
16
+ type Type ;
17
+ }
18
+
19
+ impl < ' a > AsVariantTrait for MyType < ' a > {
20
+ type Type = MyTypeVariant < ' a > ;
21
+ }
22
+
23
+ type Variant < G > = <G as AsVariantTrait >:: Type ;
24
+
25
+ fn foo < T : Default , F : FnOnce ( T ) > ( f : F ) {
26
+ let input = T :: default ( ) ;
27
+ f ( input) ;
28
+ }
29
+
30
+ fn main ( ) {
31
+ foo ( |a : Variant < MyType > | {
32
+ a. field ;
33
+ } ) ;
34
+ }
Original file line number Diff line number Diff line change
1
+ use std:: marker:: PhantomData ;
2
+
3
+ #[ derive( Default ) ]
4
+ struct MyType < ' a > {
5
+ field : usize ,
6
+ _phantom : PhantomData < & ' a ( ) > ,
7
+ }
8
+
9
+ #[ derive( Default ) ]
10
+ struct MyTypeVariant < ' a > {
11
+ field : usize ,
12
+ _phantom : PhantomData < & ' a ( ) > ,
13
+ }
14
+
15
+ trait AsVariantTrait {
16
+ type Type ;
17
+ }
18
+
19
+ impl < ' a > AsVariantTrait for MyType < ' a > {
20
+ type Type = MyTypeVariant < ' a > ;
21
+ }
22
+
23
+ fn foo < T : Default , F : FnOnce ( T ) > ( f : F ) {
24
+ let input = T :: default ( ) ;
25
+ f ( input) ;
26
+ }
27
+
28
+ fn main ( ) {
29
+ foo ( |a : <MyType as AsVariantTrait >:: Type | {
30
+ a. field ;
31
+ } ) ;
32
+ }
You can’t perform that action at this time.
0 commit comments