File tree 1 file changed +65
-0
lines changed 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ type BoxFuture < T > = std:: pin:: Pin < Box < dyn std:: future:: Future < Output = T > > > ;
2
+
3
+ fn main ( ) {
4
+ let _ = f ( ) ;
5
+ }
6
+
7
+ async fn f ( ) {
8
+ run ( "dependency" ) . await ;
9
+ }
10
+
11
+ struct InMemoryStorage ;
12
+
13
+ pub struct User < ' dep > {
14
+ pub dep : & ' dep str ,
15
+ }
16
+
17
+ impl < ' a > StorageRequest < InMemoryStorage > for SaveUser < ' a > {
18
+ fn execute ( & self ) -> BoxFuture < Result < ( ) , String > > {
19
+ todo ! ( )
20
+ }
21
+ }
22
+
23
+ trait Storage {
24
+ type Error ;
25
+ }
26
+
27
+ impl Storage for InMemoryStorage {
28
+ type Error = String ;
29
+ }
30
+
31
+ trait StorageRequestReturnType {
32
+ type Output ;
33
+ }
34
+
35
+ trait StorageRequest < S : Storage > : StorageRequestReturnType {
36
+ fn execute (
37
+ & self ,
38
+ ) -> BoxFuture < Result < <Self as StorageRequestReturnType >:: Output , <S as Storage >:: Error > > ;
39
+ }
40
+
41
+ pub struct SaveUser < ' a > {
42
+ pub name : & ' a str ,
43
+ }
44
+
45
+ impl < ' a > StorageRequestReturnType for SaveUser < ' a > {
46
+ type Output = ( ) ;
47
+ }
48
+
49
+ impl < ' dep > User < ' dep > {
50
+ async fn save < S > ( self )
51
+ where
52
+ S : Storage ,
53
+ for < ' a > SaveUser < ' a > : StorageRequest < S > ,
54
+ {
55
+ let _ = SaveUser { name : "Joe" } . execute ( ) . await ;
56
+ }
57
+ }
58
+
59
+ async fn run < S > ( dep : & str )
60
+ where
61
+ S : Storage ,
62
+ for < ' a > SaveUser < ' a > : StorageRequest < S > ,
63
+ {
64
+ User { dep } . save ( ) . await ;
65
+ }
You can’t perform that action at this time.
0 commit comments