@@ -10,6 +10,7 @@ extern crate arc_wake;
10
10
use arc_wake:: ArcWake ;
11
11
use std:: cell:: RefCell ;
12
12
use std:: future:: Future ;
13
+ use std:: marker:: PhantomData ;
13
14
use std:: sync:: Arc ;
14
15
use std:: task:: Context ;
15
16
@@ -49,6 +50,46 @@ async fn foobar(x: D, (a, _, _c): (D, D, D), _: D, _y: D) {
49
50
x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
50
51
}
51
52
53
+ struct Foo ;
54
+
55
+ impl Foo {
56
+ async fn foo ( x : D , _y : D ) {
57
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
58
+ }
59
+
60
+ async fn bar ( x : D , _: D ) {
61
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
62
+ }
63
+
64
+ async fn baz ( ( x, _) : ( D , D ) ) {
65
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
66
+ }
67
+
68
+ async fn foobar ( x : D , ( a, _, _c) : ( D , D , D ) , _: D , _y : D ) {
69
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
70
+ }
71
+ }
72
+
73
+ struct Bar < ' a > ( PhantomData < & ' a ( ) > ) ;
74
+
75
+ impl < ' a > Bar < ' a > {
76
+ async fn foo ( & ' a self , x : D , _y : D ) {
77
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
78
+ }
79
+
80
+ async fn bar ( & ' a self , x : D , _: D ) {
81
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
82
+ }
83
+
84
+ async fn baz ( & ' a self , ( x, _) : ( D , D ) ) {
85
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
86
+ }
87
+
88
+ async fn foobar ( & ' a self , x : D , ( a, _, _c) : ( D , D , D ) , _: D , _y : D ) {
89
+ x. 1 . borrow_mut ( ) . push ( DropOrder :: Function ) ;
90
+ }
91
+ }
92
+
52
93
fn main ( ) {
53
94
let empty = Arc :: new ( EmptyWaker ) ;
54
95
let waker = ArcWake :: into_waker ( empty) ;
@@ -60,6 +101,8 @@ fn main() {
60
101
// non-async functions. This is because the drop order of captured variables doesn't match the
61
102
// drop order of arguments in a function.
62
103
104
+ // Free functions
105
+
63
106
let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
64
107
let mut fut = Box :: pin ( foo ( D ( "x" , af. clone ( ) ) , D ( "_y" , af. clone ( ) ) ) ) ;
65
108
let _ = fut. as_mut ( ) . poll ( & mut cx) ;
@@ -86,4 +129,64 @@ fn main() {
86
129
assert_eq ! ( * af. borrow( ) , & [
87
130
Function , Val ( "_y" ) , Val ( "_c" ) , Val ( "a" ) , Val ( "x" ) , Val ( "_" ) , Val ( "_" ) ,
88
131
] ) ;
132
+
133
+ // Methods w/out self
134
+
135
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
136
+ let mut fut = Box :: pin ( Foo :: foo ( D ( "x" , af. clone ( ) ) , D ( "_y" , af. clone ( ) ) ) ) ;
137
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
138
+ assert_eq ! ( * af. borrow( ) , & [ Function , Val ( "_y" ) , Val ( "x" ) ] ) ;
139
+
140
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
141
+ let mut fut = Box :: pin ( Foo :: bar ( D ( "x" , af. clone ( ) ) , D ( "_" , af. clone ( ) ) ) ) ;
142
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
143
+ assert_eq ! ( * af. borrow( ) , & [ Function , Val ( "x" ) , Val ( "_" ) ] ) ;
144
+
145
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
146
+ let mut fut = Box :: pin ( Foo :: baz ( ( D ( "x" , af. clone ( ) ) , D ( "_" , af. clone ( ) ) ) ) ) ;
147
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
148
+ assert_eq ! ( * af. borrow( ) , & [ Function , Val ( "x" ) , Val ( "_" ) ] ) ;
149
+
150
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
151
+ let mut fut = Box :: pin ( Foo :: foobar (
152
+ D ( "x" , af. clone ( ) ) ,
153
+ ( D ( "a" , af. clone ( ) ) , D ( "_" , af. clone ( ) ) , D ( "_c" , af. clone ( ) ) ) ,
154
+ D ( "_" , af. clone ( ) ) ,
155
+ D ( "_y" , af. clone ( ) ) ,
156
+ ) ) ;
157
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
158
+ assert_eq ! ( * af. borrow( ) , & [
159
+ Function , Val ( "_y" ) , Val ( "_c" ) , Val ( "a" ) , Val ( "x" ) , Val ( "_" ) , Val ( "_" ) ,
160
+ ] ) ;
161
+
162
+ // Methods
163
+
164
+ let b = Bar ( Default :: default ( ) ) ;
165
+
166
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
167
+ let mut fut = Box :: pin ( b. foo ( D ( "x" , af. clone ( ) ) , D ( "_y" , af. clone ( ) ) ) ) ;
168
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
169
+ assert_eq ! ( * af. borrow( ) , & [ Function , Val ( "_y" ) , Val ( "x" ) ] ) ;
170
+
171
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
172
+ let mut fut = Box :: pin ( b. bar ( D ( "x" , af. clone ( ) ) , D ( "_" , af. clone ( ) ) ) ) ;
173
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
174
+ assert_eq ! ( * af. borrow( ) , & [ Function , Val ( "x" ) , Val ( "_" ) ] ) ;
175
+
176
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
177
+ let mut fut = Box :: pin ( b. baz ( ( D ( "x" , af. clone ( ) ) , D ( "_" , af. clone ( ) ) ) ) ) ;
178
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
179
+ assert_eq ! ( * af. borrow( ) , & [ Function , Val ( "x" ) , Val ( "_" ) ] ) ;
180
+
181
+ let af = Arc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ;
182
+ let mut fut = Box :: pin ( b. foobar (
183
+ D ( "x" , af. clone ( ) ) ,
184
+ ( D ( "a" , af. clone ( ) ) , D ( "_" , af. clone ( ) ) , D ( "_c" , af. clone ( ) ) ) ,
185
+ D ( "_" , af. clone ( ) ) ,
186
+ D ( "_y" , af. clone ( ) ) ,
187
+ ) ) ;
188
+ let _ = fut. as_mut ( ) . poll ( & mut cx) ;
189
+ assert_eq ! ( * af. borrow( ) , & [
190
+ Function , Val ( "_y" ) , Val ( "_c" ) , Val ( "a" ) , Val ( "x" ) , Val ( "_" ) , Val ( "_" ) ,
191
+ ] ) ;
89
192
}
0 commit comments