@@ -2,7 +2,7 @@ use std::cell::RefCell;
22use std:: marker:: PhantomData ;
33use std:: rc:: Rc ;
44
5- use capnp:: capability:: { Promise , FromClientHook } ;
5+ use capnp:: capability:: { FromClientHook , Promise } ;
66use capnp:: private:: capability:: { ClientHook , RequestHook } ;
77use futures:: TryFutureExt ;
88
@@ -25,19 +25,18 @@ struct ClientInner<F, C> {
2525}
2626
2727impl < 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 ,
3132{
3233 fn get_current ( & mut self ) -> Box < dyn ClientHook > {
3334 if let Some ( hook) = self . current . as_ref ( ) {
3435 hook. add_ref ( )
3536 } else {
3637 let hook = match ( self . connect ) ( ) {
3738 Ok ( hook) => hook. into_client_hook ( ) ,
38- Err ( err) => {
39- crate :: broken:: new_cap ( err)
40- }
39+ Err ( err) => crate :: broken:: new_cap ( err) ,
4140 } ;
4241 self . current = Some ( hook. add_ref ( ) ) ;
4342 hook
@@ -50,10 +49,11 @@ struct Client<F, C> {
5049}
5150
5251impl < 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 ,
5757{
5858 pub fn new ( connect : F ) -> Client < F , C > {
5959 Client {
@@ -62,16 +62,15 @@ impl<F, C> Client<F, C>
6262 generation : 0 ,
6363 current : None ,
6464 marker : PhantomData ,
65- } ) )
65+ } ) ) ,
6666 }
6767 }
6868
6969 pub fn get_current ( & self ) -> Box < dyn ClientHook > {
7070 self . inner . borrow_mut ( ) . get_current ( )
7171 }
7272
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 > {
7574 let c = self . clone ( ) ;
7675 let generation = self . inner . borrow ( ) . generation ;
7776 Promise :: from_future ( promise. map_err ( move |err| {
@@ -81,9 +80,7 @@ impl<F, C> Client<F, C>
8180 let mut inner = c. inner . borrow_mut ( ) ;
8281 inner. generation = generation + 1 ;
8382 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 ( ) ) ,
8784 Err ( err) => inner. current = Some ( crate :: broken:: new_cap ( err) ) ,
8885 }
8986 }
@@ -93,9 +90,10 @@ impl<F, C> Client<F, C>
9390}
9491
9592impl < 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 ,
9997{
10098 fn add_ref ( & self ) -> Box < dyn SetTarget < C > > {
10199 Box :: new ( self . clone ( ) )
@@ -108,37 +106,46 @@ impl<F: 'static, C> SetTarget<C> for Client<F, C>
108106
109107impl < F , C > Clone for Client < F , C > {
110108 fn clone ( & self ) -> Self {
111- Self { inner : self . inner . clone ( ) }
109+ Self {
110+ inner : self . inner . clone ( ) ,
111+ }
112112 }
113113}
114114
115115impl < 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 ,
120121{
121122 fn add_ref ( & self ) -> Box < dyn ClientHook > {
122123 Box :: new ( self . clone ( ) )
123124 }
124125
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) ;
132135 let hook = Request :: new ( self . clone ( ) , result. hook ) ;
133136 capnp:: capability:: Request :: new ( Box :: new ( hook) )
134137 }
135138
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) ;
142149 self . wrap ( result)
143150 }
144151
@@ -147,7 +154,7 @@ impl<F, C> ClientHook for Client<F, C>
147154 }
148155
149156 fn get_ptr ( & self ) -> usize {
150- ( self . inner . as_ref ( ) ) as * const _ as usize
157+ ( self . inner . as_ref ( ) ) as * const _ as usize
151158 }
152159
153160 fn get_resolved ( & self ) -> Option < Box < dyn ClientHook > > {
@@ -175,10 +182,11 @@ impl<F, C> Request<F, C> {
175182}
176183
177184impl < 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 ,
182190{
183191 fn get ( & mut self ) -> capnp:: any_pointer:: Builder < ' _ > {
184192 self . inner . get ( )
@@ -195,33 +203,39 @@ impl<F, C> RequestHook for Request<F, C>
195203 result
196204 }
197205
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+ ) > {
200213 todo ! ( )
201214 }
202215}
203216
204217pub 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 ,
209223{
210224 let current = connect ( ) ?;
211225 let c = Client :: new ( connect) ;
212226 c. set_target ( current) ;
213- let hook : Box < dyn ClientHook > = Box :: new ( c. clone ( ) ) ;
227+ let hook: Box < dyn ClientHook > = Box :: new ( c. clone ( ) ) ;
214228 Ok ( ( FromClientHook :: new ( hook) , Box :: new ( c) ) )
215229}
216230
217-
218231pub 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 ,
223237{
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 ( ) ) ;
226240 ( FromClientHook :: new ( hook) , Box :: new ( c) )
227- }
241+ }
0 commit comments