Skip to content

Commit f9665a0

Browse files
committed
cargo fmt
1 parent 1323d6c commit f9665a0

File tree

4 files changed

+184
-124
lines changed

4 files changed

+184
-124
lines changed

capnp-rpc/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use std::task::{Context, Poll};
7171
pub use crate::rpc::Disconnector;
7272
use crate::task_set::TaskSet;
7373

74-
pub use crate::reconnect::{lazy_auto_reconnect, auto_reconnect, SetTarget};
74+
pub use crate::reconnect::{auto_reconnect, lazy_auto_reconnect, SetTarget};
7575

7676
/// Code generated from
7777
/// [rpc.capnp](https://github.com/sandstorm-io/capnproto/blob/master/c%2B%2B/src/capnp/rpc.capnp).
@@ -101,11 +101,11 @@ mod attach;
101101
mod broken;
102102
mod local;
103103
mod queued;
104+
mod reconnect;
104105
mod rpc;
105106
mod sender_queue;
106107
mod split;
107108
mod task_set;
108-
mod reconnect;
109109
pub mod twoparty;
110110

111111
pub trait OutgoingMessage {

capnp-rpc/src/reconnect.rs

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cell::RefCell;
22
use std::marker::PhantomData;
33
use std::rc::Rc;
44

5-
use capnp::capability::{Promise, FromClientHook};
5+
use capnp::capability::{FromClientHook, Promise};
66
use capnp::private::capability::{ClientHook, RequestHook};
77
use futures::TryFutureExt;
88

@@ -25,19 +25,18 @@ struct ClientInner<F, C> {
2525
}
2626

2727
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,
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

5251
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,
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

9592
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,
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

109107
impl<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

115115
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,
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

177184
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,
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

204217
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,
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-
218231
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,
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

Comments
 (0)