2
2
use std:: future:: Future ;
3
3
use crate :: { get_driver, Context } ;
4
4
5
+ /// Allows to create an event handler based on 1 parameter
5
6
pub fn bind < T1 : Clone > ( param1 : & T1 ) -> Bind1 < T1 > {
6
7
let param1 = param1. clone ( ) ;
7
8
@@ -10,18 +11,21 @@ pub fn bind<T1: Clone>(param1: &T1) -> Bind1<T1> {
10
11
}
11
12
}
12
13
14
+ /// Event handler factory having 1 parameter in context
13
15
pub struct Bind1 < T1 > {
14
16
param1 : T1 ,
15
17
}
16
18
17
19
impl < T1 : Clone > Bind1 < T1 > {
20
+ /// Extend this creator to a 2-parameter one
18
21
pub fn and < T2 : Clone > ( self , param2 : & T2 ) -> Bind2 < T1 , T2 > {
19
22
Bind2 {
20
23
param1 : self . param1 ,
21
24
param2 : param2. clone ( ) ,
22
25
}
23
26
}
24
27
28
+ /// Create event handler that doesn't accept a parameter
25
29
pub fn call < R > ( self , fun : fn ( & Context , & T1 ) -> R ) -> impl Fn ( ) -> R {
26
30
let Self { param1 } = self ;
27
31
@@ -31,6 +35,7 @@ impl<T1: Clone> Bind1<T1> {
31
35
}
32
36
}
33
37
38
+ /// Create event handler that accepts a parameter
34
39
pub fn call_param < T2 , R > ( self , fun : fn ( & Context , & T1 , T2 ) -> R ) -> impl Fn ( T2 ) -> R {
35
40
let Self { param1 } = self ;
36
41
@@ -40,6 +45,7 @@ impl<T1: Clone> Bind1<T1> {
40
45
}
41
46
}
42
47
48
+ /// Run async code
43
49
pub fn spawn <
44
50
Fut : Future < Output =Context > + ' static
45
51
> ( self , fun : fn ( Context , T1 ) -> Fut ) -> impl Fn ( ) {
@@ -56,19 +62,22 @@ impl<T1: Clone> Bind1<T1> {
56
62
}
57
63
}
58
64
65
+ /// Allows to create an event handler based on 2 parameters
59
66
pub fn bind2 < T1 : Clone , T2 : Clone > ( param1 : & T1 , param2 : & T2 ) -> Bind2 < T1 , T2 > {
60
67
Bind2 {
61
68
param1 : param1. clone ( ) ,
62
69
param2 : param2. clone ( )
63
70
}
64
71
}
65
72
73
+ /// Event handler factory having 2 parameters in context
66
74
pub struct Bind2 < T1 , T2 > {
67
75
param1 : T1 ,
68
76
param2 : T2 ,
69
77
}
70
78
71
79
impl < T1 : Clone , T2 : Clone > Bind2 < T1 , T2 > {
80
+ /// Extend this creator to a 3-parameter one
72
81
pub fn and < T3 : Clone > ( self , param3 : & T3 ) -> Bind3 < T1 , T2 , T3 > {
73
82
Bind3 {
74
83
param1 : self . param1 ,
@@ -77,6 +86,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
77
86
}
78
87
}
79
88
89
+ /// Create event handler that doesn't accept a parameter
80
90
pub fn call < R > ( self , fun : fn ( & Context , & T1 , & T2 ) -> R ) -> impl Fn ( ) -> R {
81
91
let Self { param1, param2 } = self ;
82
92
@@ -86,6 +96,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
86
96
}
87
97
}
88
98
99
+ /// Create event handler that accepts a parameter
89
100
pub fn call_param < T3 , R > ( self , fun : fn ( & Context , & T1 , & T2 , T3 ) -> R ) -> impl Fn ( T3 ) -> R {
90
101
let Self { param1, param2 } = self ;
91
102
@@ -95,6 +106,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
95
106
}
96
107
}
97
108
109
+ /// Run async code
98
110
pub fn spawn <
99
111
Fut : Future < Output =Context > + ' static
100
112
> ( self , fun : fn ( Context , T1 , T2 ) -> Fut ) -> impl Fn ( ) {
@@ -112,6 +124,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
112
124
}
113
125
}
114
126
127
+ /// Allows to create an event handler based on 3 parameters
115
128
pub fn bind3 < T1 : Clone , T2 : Clone , T3 : Clone > ( param1 : & T1 , param2 : & T2 , param3 : & T3 ) -> Bind3 < T1 , T2 , T3 > {
116
129
Bind3 {
117
130
param1 : param1. clone ( ) ,
@@ -120,13 +133,15 @@ pub fn bind3<T1: Clone, T2: Clone, T3: Clone>(param1: &T1, param2: &T2, param3:
120
133
}
121
134
}
122
135
136
+ /// Event handler factory having 3 parameters in context
123
137
pub struct Bind3 < T1 , T2 , T3 > {
124
138
param1 : T1 ,
125
139
param2 : T2 ,
126
140
param3 : T3 ,
127
141
}
128
142
129
143
impl < T1 : Clone , T2 : Clone , T3 : Clone > Bind3 < T1 , T2 , T3 > {
144
+ /// Extend this creator to a 4-parameter one
130
145
pub fn and < T4 : Clone > ( self , param4 : & T4 ) -> Bind4 < T1 , T2 , T3 , T4 > {
131
146
Bind4 {
132
147
param1 : self . param1 ,
@@ -136,6 +151,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
136
151
}
137
152
}
138
153
154
+ /// Create event handler that doesn't accept a parameter
139
155
pub fn call < R > ( self , fun : fn ( & Context , & T1 , & T2 , & T3 ) -> R ) -> impl Fn ( ) -> R {
140
156
let Self { param1, param2, param3 } = self ;
141
157
@@ -145,6 +161,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
145
161
}
146
162
}
147
163
164
+ /// Create event handler that accepts a parameter
148
165
pub fn call_param < T4 , R > ( self , fun : fn ( & Context , & T1 , & T2 , & T3 , T4 ) -> R ) -> impl Fn ( T4 ) -> R {
149
166
let Self { param1, param2, param3 } = self ;
150
167
@@ -154,6 +171,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
154
171
}
155
172
}
156
173
174
+ /// Run async code
157
175
pub fn spawn <
158
176
Fut : Future < Output =Context > + ' static
159
177
> ( self , fun : fn ( Context , T1 , T2 , T3 ) -> Fut ) -> impl Fn ( ) {
@@ -172,6 +190,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
172
190
}
173
191
}
174
192
193
+ /// Allows to create an event handler based on 4 parameters
175
194
pub fn bind4 < T1 : Clone , T2 : Clone , T3 : Clone , T4 : Clone > ( param1 : & T1 , param2 : & T2 , param3 : & T3 , param4 : & T4 ) -> Bind4 < T1 , T2 , T3 , T4 > {
176
195
Bind4 {
177
196
param1 : param1. clone ( ) ,
@@ -181,6 +200,7 @@ pub fn bind4<T1: Clone, T2: Clone, T3: Clone, T4: Clone>(param1: &T1, param2: &T
181
200
}
182
201
}
183
202
203
+ /// Event handler factory having 4 parameters in context
184
204
pub struct Bind4 < T1 , T2 , T3 , T4 > {
185
205
param1 : T1 ,
186
206
param2 : T2 ,
@@ -189,6 +209,7 @@ pub struct Bind4<T1, T2, T3, T4> {
189
209
}
190
210
191
211
impl < T1 : Clone , T2 : Clone , T3 : Clone , T4 : Clone > Bind4 < T1 , T2 , T3 , T4 > {
212
+ /// Create event handler that doesn't accept a parameter
192
213
pub fn call < R > ( self , fun : fn ( & Context , & T1 , & T2 , & T3 , & T4 ) -> R ) -> impl Fn ( ) -> R {
193
214
let Self { param1, param2, param3, param4 } = self ;
194
215
@@ -198,6 +219,7 @@ impl<T1: Clone, T2: Clone, T3: Clone, T4: Clone> Bind4<T1, T2, T3, T4> {
198
219
}
199
220
}
200
221
222
+ /// Create event handler that accepts a parameter
201
223
pub fn call_param < T5 , R > ( self , fun : fn ( & Context , & T1 , & T2 , & T3 , & T4 , T5 ) -> R ) -> impl Fn ( T5 ) -> R {
202
224
let Self { param1, param2, param3, param4 } = self ;
203
225
@@ -207,6 +229,7 @@ impl<T1: Clone, T2: Clone, T3: Clone, T4: Clone> Bind4<T1, T2, T3, T4> {
207
229
}
208
230
}
209
231
232
+ /// Run async code
210
233
pub fn spawn <
211
234
Fut : Future < Output =Context > + ' static ,
212
235
> ( self , fun : fn ( Context , T1 , T2 , T3 , T4 ) -> Fut ) -> impl Fn ( ) {
0 commit comments