@@ -2,7 +2,7 @@ use std::cell::RefCell;
2
2
use std:: marker:: PhantomData ;
3
3
use std:: rc:: Rc ;
4
4
5
- use capnp:: capability:: { Promise , FromClientHook } ;
5
+ use capnp:: capability:: { FromClientHook , Promise } ;
6
6
use capnp:: private:: capability:: { ClientHook , RequestHook } ;
7
7
use futures:: TryFutureExt ;
8
8
@@ -25,19 +25,18 @@ struct ClientInner<F, C> {
25
25
}
26
26
27
27
impl < F , C > ClientInner < F , C >
28
- where F : FnMut ( ) -> capnp:: Result < C > ,
29
- F : ' static ,
30
- C : FromClientHook ,
28
+ where
29
+ F : FnMut ( ) -> capnp:: Result < C > ,
30
+ F : ' static ,
31
+ C : FromClientHook ,
31
32
{
32
33
fn get_current ( & mut self ) -> Box < dyn ClientHook > {
33
34
if let Some ( hook) = self . current . as_ref ( ) {
34
35
hook. add_ref ( )
35
36
} else {
36
37
let hook = match ( self . connect ) ( ) {
37
38
Ok ( hook) => hook. into_client_hook ( ) ,
38
- Err ( err) => {
39
- crate :: broken:: new_cap ( err)
40
- }
39
+ Err ( err) => crate :: broken:: new_cap ( err) ,
41
40
} ;
42
41
self . current = Some ( hook. add_ref ( ) ) ;
43
42
hook
@@ -50,10 +49,11 @@ struct Client<F, C> {
50
49
}
51
50
52
51
impl < F , C > Client < F , C >
53
- where F : FnMut ( ) -> capnp:: Result < C > ,
54
- F : ' static ,
55
- C : FromClientHook ,
56
- C : ' static ,
52
+ where
53
+ F : FnMut ( ) -> capnp:: Result < C > ,
54
+ F : ' static ,
55
+ C : FromClientHook ,
56
+ C : ' static ,
57
57
{
58
58
pub fn new ( connect : F ) -> Client < F , C > {
59
59
Client {
@@ -62,16 +62,15 @@ impl<F, C> Client<F, C>
62
62
generation : 0 ,
63
63
current : None ,
64
64
marker : PhantomData ,
65
- } ) )
65
+ } ) ) ,
66
66
}
67
67
}
68
68
69
69
pub fn get_current ( & self ) -> Box < dyn ClientHook > {
70
70
self . inner . borrow_mut ( ) . get_current ( )
71
71
}
72
72
73
- fn wrap < T : ' static > ( & self , promise : Promise < T , capnp:: Error > ) -> Promise < T , capnp:: Error >
74
- {
73
+ fn wrap < T : ' static > ( & self , promise : Promise < T , capnp:: Error > ) -> Promise < T , capnp:: Error > {
75
74
let c = self . clone ( ) ;
76
75
let generation = self . inner . borrow ( ) . generation ;
77
76
Promise :: from_future ( promise. map_err ( move |err| {
@@ -81,9 +80,7 @@ impl<F, C> Client<F, C>
81
80
let mut inner = c. inner . borrow_mut ( ) ;
82
81
inner. generation = generation + 1 ;
83
82
match ( inner. connect ) ( ) {
84
- Ok ( hook) => {
85
- inner. current = Some ( hook. into_client_hook ( ) )
86
- }
83
+ Ok ( hook) => inner. current = Some ( hook. into_client_hook ( ) ) ,
87
84
Err ( err) => inner. current = Some ( crate :: broken:: new_cap ( err) ) ,
88
85
}
89
86
}
@@ -93,9 +90,10 @@ impl<F, C> Client<F, C>
93
90
}
94
91
95
92
impl < F : ' static , C > SetTarget < C > for Client < F , C >
96
- where F : ' static ,
97
- C : FromClientHook ,
98
- C : ' static ,
93
+ where
94
+ F : ' static ,
95
+ C : FromClientHook ,
96
+ C : ' static ,
99
97
{
100
98
fn add_ref ( & self ) -> Box < dyn SetTarget < C > > {
101
99
Box :: new ( self . clone ( ) )
@@ -108,37 +106,46 @@ impl<F: 'static, C> SetTarget<C> for Client<F, C>
108
106
109
107
impl < F , C > Clone for Client < F , C > {
110
108
fn clone ( & self ) -> Self {
111
- Self { inner : self . inner . clone ( ) }
109
+ Self {
110
+ inner : self . inner . clone ( ) ,
111
+ }
112
112
}
113
113
}
114
114
115
115
impl < F , C > ClientHook for Client < F , C >
116
- where F : FnMut ( ) -> capnp:: Result < C > ,
117
- F : ' static ,
118
- C : FromClientHook ,
119
- C : ' static ,
116
+ where
117
+ F : FnMut ( ) -> capnp:: Result < C > ,
118
+ F : ' static ,
119
+ C : FromClientHook ,
120
+ C : ' static ,
120
121
{
121
122
fn add_ref ( & self ) -> Box < dyn ClientHook > {
122
123
Box :: new ( self . clone ( ) )
123
124
}
124
125
125
- fn new_call ( & self ,
126
- interface_id : u64 ,
127
- method_id : u16 ,
128
- size_hint : Option < capnp:: MessageSize > )
129
- -> capnp:: capability:: Request < capnp:: any_pointer:: Owned , capnp:: any_pointer:: Owned >
130
- {
131
- let result = self . get_current ( ) . new_call ( interface_id, method_id, size_hint) ;
126
+ fn new_call (
127
+ & self ,
128
+ interface_id : u64 ,
129
+ method_id : u16 ,
130
+ size_hint : Option < capnp:: MessageSize > ,
131
+ ) -> capnp:: capability:: Request < capnp:: any_pointer:: Owned , capnp:: any_pointer:: Owned > {
132
+ let result = self
133
+ . get_current ( )
134
+ . new_call ( interface_id, method_id, size_hint) ;
132
135
let hook = Request :: new ( self . clone ( ) , result. hook ) ;
133
136
capnp:: capability:: Request :: new ( Box :: new ( hook) )
134
137
}
135
138
136
- fn call ( & self , interface_id : u64 , method_id : u16 ,
137
- params : Box < dyn capnp:: private:: capability:: ParamsHook > ,
138
- results : Box < dyn capnp:: private:: capability:: ResultsHook > )
139
- -> Promise < ( ) , capnp:: Error >
140
- {
141
- let result = self . get_current ( ) . call ( interface_id, method_id, params, results) ;
139
+ fn call (
140
+ & self ,
141
+ interface_id : u64 ,
142
+ method_id : u16 ,
143
+ params : Box < dyn capnp:: private:: capability:: ParamsHook > ,
144
+ results : Box < dyn capnp:: private:: capability:: ResultsHook > ,
145
+ ) -> Promise < ( ) , capnp:: Error > {
146
+ let result = self
147
+ . get_current ( )
148
+ . call ( interface_id, method_id, params, results) ;
142
149
self . wrap ( result)
143
150
}
144
151
@@ -147,7 +154,7 @@ impl<F, C> ClientHook for Client<F, C>
147
154
}
148
155
149
156
fn get_ptr ( & self ) -> usize {
150
- ( self . inner . as_ref ( ) ) as * const _ as usize
157
+ ( self . inner . as_ref ( ) ) as * const _ as usize
151
158
}
152
159
153
160
fn get_resolved ( & self ) -> Option < Box < dyn ClientHook > > {
@@ -175,10 +182,11 @@ impl<F, C> Request<F, C> {
175
182
}
176
183
177
184
impl < F , C > RequestHook for Request < F , C >
178
- where F : FnMut ( ) -> capnp:: Result < C > ,
179
- F : ' static ,
180
- C : FromClientHook ,
181
- C : ' static ,
185
+ where
186
+ F : FnMut ( ) -> capnp:: Result < C > ,
187
+ F : ' static ,
188
+ C : FromClientHook ,
189
+ C : ' static ,
182
190
{
183
191
fn get ( & mut self ) -> capnp:: any_pointer:: Builder < ' _ > {
184
192
self . inner . get ( )
@@ -195,33 +203,39 @@ impl<F, C> RequestHook for Request<F, C>
195
203
result
196
204
}
197
205
198
- fn tail_send ( self : Box < Self > )
199
- -> Option < ( u32 , Promise < ( ) , capnp:: Error > , Box < dyn capnp:: private:: capability:: PipelineHook > ) > {
206
+ fn tail_send (
207
+ self : Box < Self > ,
208
+ ) -> Option < (
209
+ u32 ,
210
+ Promise < ( ) , capnp:: Error > ,
211
+ Box < dyn capnp:: private:: capability:: PipelineHook > ,
212
+ ) > {
200
213
todo ! ( )
201
214
}
202
215
}
203
216
204
217
pub fn auto_reconnect < F , C > ( mut connect : F ) -> capnp:: Result < ( C , Box < dyn SetTarget < C > > ) >
205
- where F : FnMut ( ) -> capnp:: Result < C > ,
206
- F : ' static ,
207
- C : FromClientHook ,
208
- C : ' static ,
218
+ where
219
+ F : FnMut ( ) -> capnp:: Result < C > ,
220
+ F : ' static ,
221
+ C : FromClientHook ,
222
+ C : ' static ,
209
223
{
210
224
let current = connect ( ) ?;
211
225
let c = Client :: new ( connect) ;
212
226
c. set_target ( current) ;
213
- let hook : Box < dyn ClientHook > = Box :: new ( c. clone ( ) ) ;
227
+ let hook: Box < dyn ClientHook > = Box :: new ( c. clone ( ) ) ;
214
228
Ok ( ( FromClientHook :: new ( hook) , Box :: new ( c) ) )
215
229
}
216
230
217
-
218
231
pub fn lazy_auto_reconnect < F , C > ( connect : F ) -> ( C , Box < dyn SetTarget < C > > )
219
- where F : FnMut ( ) -> capnp:: Result < C > ,
220
- F : ' static ,
221
- C : FromClientHook ,
222
- C : ' static ,
232
+ where
233
+ F : FnMut ( ) -> capnp:: Result < C > ,
234
+ F : ' static ,
235
+ C : FromClientHook ,
236
+ C : ' static ,
223
237
{
224
- let c : Client < F , C > = Client :: new ( connect) ;
225
- let hook : Box < dyn ClientHook > = Box :: new ( c. clone ( ) ) ;
238
+ let c: Client < F , C > = Client :: new ( connect) ;
239
+ let hook: Box < dyn ClientHook > = Box :: new ( c. clone ( ) ) ;
226
240
( FromClientHook :: new ( hook) , Box :: new ( c) )
227
- }
241
+ }
0 commit comments