Skip to content

Commit 31ec6d6

Browse files
dvc94chtomusdrw
authored andcommitted
Use rustfmt (#407)
* Use rustfmt. * Run rustfmt.
1 parent c24ce48 commit 31ec6d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2740
-2187
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ matrix:
2121
allow_failures:
2222
- rust: nightly
2323

24+
before_script:
25+
- rustup component add rustfmt
26+
2427
script:
2528
- cargo build --all
2629
- cargo test --all
30+
- |
31+
([ $TRAVIS_RUST_VERSION = stable ] && cargo fmt --all -- --check) || true
2732
2833
after_success: |
2934
[ $TRAVIS_OS_NAME == 'linux' ] &&

core/examples/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use jsonrpc_core::*;
21
use jsonrpc_core::futures::Future;
2+
use jsonrpc_core::*;
33

44
fn main() {
55
let mut io = IoHandler::new();

core/examples/basic.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use jsonrpc_core::*;
33
fn main() {
44
let mut io = IoHandler::new();
55

6-
io.add_method("say_hello", |_: Params| {
7-
Ok(Value::String("Hello World!".to_owned()))
8-
});
6+
io.add_method("say_hello", |_: Params| Ok(Value::String("Hello World!".to_owned())));
97

108
let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
119
let response = r#"{"jsonrpc":"2.0","result":"hello","id":1}"#;

core/examples/meta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use jsonrpc_core::*;
21
use jsonrpc_core::futures::Future;
2+
use jsonrpc_core::*;
33

44
#[derive(Clone, Default)]
55
struct Meta(usize);

core/examples/middlewares.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::time::Instant;
2-
use std::sync::atomic::{self, AtomicUsize};
3-
use jsonrpc_core::*;
4-
use jsonrpc_core::futures::Future;
51
use jsonrpc_core::futures::future::Either;
2+
use jsonrpc_core::futures::Future;
3+
use jsonrpc_core::*;
4+
use std::sync::atomic::{self, AtomicUsize};
5+
use std::time::Instant;
66

77
#[derive(Clone, Debug)]
88
struct Meta(usize);
@@ -14,9 +14,10 @@ impl Middleware<Meta> for MyMiddleware {
1414
type Future = FutureResponse;
1515
type CallFuture = middleware::NoopCallFuture;
1616

17-
fn on_request<F, X>(&self, request: Request, meta: Meta, next: F) -> Either<Self::Future, X> where
17+
fn on_request<F, X>(&self, request: Request, meta: Meta, next: F) -> Either<Self::Future, X>
18+
where
1819
F: FnOnce(Request, Meta) -> X + Send,
19-
X: Future<Item=Option<Response>, Error=()> + Send + 'static,
20+
X: Future<Item = Option<Response>, Error = ()> + Send + 'static,
2021
{
2122
let start = Instant::now();
2223
let request_number = self.0.fetch_add(1, atomic::Ordering::SeqCst);

core/examples/params.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use jsonrpc_core::*;
2-
use serde_derive::{Deserialize};
2+
use serde_derive::Deserialize;
33

44
#[derive(Deserialize)]
55
struct HelloParams {
6-
name:String,
6+
name: String,
77
}
88

99
fn main() {
1010
let mut io = IoHandler::new();
1111

1212
io.add_method("say_hello", |params: Params| {
13-
let parsed: HelloParams = params.parse().unwrap();
13+
let parsed: HelloParams = params.parse().unwrap();
1414
Ok(Value::String(format!("hello, {}", parsed.name)))
1515
});
1616

core/src/calls.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crate::types::{Error, Params, Value};
2+
use crate::BoxFuture;
3+
use futures::{Future, IntoFuture};
14
use std::fmt;
25
use std::sync::Arc;
3-
use crate::types::{Params, Value, Error};
4-
use futures::{Future, IntoFuture};
5-
use crate::BoxFuture;
66

77
/// Metadata trait
88
pub trait Metadata: Clone + Send + 'static {}
@@ -54,12 +54,13 @@ impl<T: Metadata> fmt::Debug for RemoteProcedure<T> {
5454
match *self {
5555
Method(..) => write!(fmt, "<method>"),
5656
Notification(..) => write!(fmt, "<notification>"),
57-
Alias(ref alias) => write!(fmt, "alias => {:?}", alias)
57+
Alias(ref alias) => write!(fmt, "alias => {:?}", alias),
5858
}
5959
}
6060
}
6161

62-
impl<F: Send + Sync + 'static, X: Send + 'static, I> RpcMethodSimple for F where
62+
impl<F: Send + Sync + 'static, X: Send + 'static, I> RpcMethodSimple for F
63+
where
6364
F: Fn(Params) -> I,
6465
X: Future<Item = Value, Error = Error>,
6566
I: IntoFuture<Item = Value, Error = Error, Future = X>,
@@ -70,15 +71,17 @@ impl<F: Send + Sync + 'static, X: Send + 'static, I> RpcMethodSimple for F where
7071
}
7172
}
7273

73-
impl<F: Send + Sync + 'static> RpcNotificationSimple for F where
74+
impl<F: Send + Sync + 'static> RpcNotificationSimple for F
75+
where
7476
F: Fn(Params),
7577
{
7678
fn execute(&self, params: Params) {
7779
self(params)
7880
}
7981
}
8082

81-
impl<F: Send + Sync + 'static, X: Send + 'static, T, I> RpcMethod<T> for F where
83+
impl<F: Send + Sync + 'static, X: Send + 'static, T, I> RpcMethod<T> for F
84+
where
8285
T: Metadata,
8386
F: Fn(Params, T) -> I,
8487
I: IntoFuture<Item = Value, Error = Error, Future = X>,
@@ -89,7 +92,8 @@ impl<F: Send + Sync + 'static, X: Send + 'static, T, I> RpcMethod<T> for F where
8992
}
9093
}
9194

92-
impl<F: Send + Sync + 'static, T> RpcNotification<T> for F where
95+
impl<F: Send + Sync + 'static, T> RpcNotification<T> for F
96+
where
9397
T: Metadata,
9498
F: Fn(Params, T),
9599
{

core/src/delegates.rs

+36-24
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
//! Delegate rpc calls
22
3-
use std::sync::Arc;
43
use std::collections::HashMap;
4+
use std::sync::Arc;
55

6-
use crate::types::{Params, Value, Error};
76
use crate::calls::{Metadata, RemoteProcedure, RpcMethod, RpcNotification};
8-
use futures::IntoFuture;
7+
use crate::types::{Error, Params, Value};
98
use crate::BoxFuture;
9+
use futures::IntoFuture;
1010

1111
struct DelegateAsyncMethod<T, F> {
1212
delegate: Arc<T>,
1313
closure: F,
1414
}
1515

16-
impl<T, M, F, I> RpcMethod<M> for DelegateAsyncMethod<T, F> where
16+
impl<T, M, F, I> RpcMethod<M> for DelegateAsyncMethod<T, F>
17+
where
1718
M: Metadata,
1819
F: Fn(&T, Params) -> I,
1920
I: IntoFuture<Item = Value, Error = Error>,
@@ -32,7 +33,8 @@ struct DelegateMethodWithMeta<T, F> {
3233
closure: F,
3334
}
3435

35-
impl<T, M, F, I> RpcMethod<M> for DelegateMethodWithMeta<T, F> where
36+
impl<T, M, F, I> RpcMethod<M> for DelegateMethodWithMeta<T, F>
37+
where
3638
M: Metadata,
3739
F: Fn(&T, Params, M) -> I,
3840
I: IntoFuture<Item = Value, Error = Error>,
@@ -51,7 +53,8 @@ struct DelegateNotification<T, F> {
5153
closure: F,
5254
}
5355

54-
impl<T, M, F> RpcNotification<M> for DelegateNotification<T, F> where
56+
impl<T, M, F> RpcNotification<M> for DelegateNotification<T, F>
57+
where
5558
F: Fn(&T, Params) + 'static,
5659
F: Send + Sync + 'static,
5760
T: Send + Sync + 'static,
@@ -64,15 +67,17 @@ impl<T, M, F> RpcNotification<M> for DelegateNotification<T, F> where
6467
}
6568

6669
/// A set of RPC methods and notifications tied to single `delegate` struct.
67-
pub struct IoDelegate<T, M = ()> where
70+
pub struct IoDelegate<T, M = ()>
71+
where
6872
T: Send + Sync + 'static,
6973
M: Metadata,
7074
{
7175
delegate: Arc<T>,
7276
methods: HashMap<String, RemoteProcedure<M>>,
7377
}
7478

75-
impl<T, M> IoDelegate<T, M> where
79+
impl<T, M> IoDelegate<T, M>
80+
where
7681
T: Send + Sync + 'static,
7782
M: Metadata,
7883
{
@@ -91,50 +96,57 @@ impl<T, M> IoDelegate<T, M> where
9196
}
9297

9398
/// Adds async method to the delegate.
94-
pub fn add_method<F, I>(&mut self, name: &str, method: F) where
99+
pub fn add_method<F, I>(&mut self, name: &str, method: F)
100+
where
95101
F: Fn(&T, Params) -> I,
96102
I: IntoFuture<Item = Value, Error = Error>,
97103
F: Send + Sync + 'static,
98104
I::Future: Send + 'static,
99105
{
100-
self.methods.insert(name.into(), RemoteProcedure::Method(Arc::new(
101-
DelegateAsyncMethod {
106+
self.methods.insert(
107+
name.into(),
108+
RemoteProcedure::Method(Arc::new(DelegateAsyncMethod {
102109
delegate: self.delegate.clone(),
103110
closure: method,
104-
}
105-
)));
111+
})),
112+
);
106113
}
107114

108115
/// Adds async method with metadata to the delegate.
109-
pub fn add_method_with_meta<F, I>(&mut self, name: &str, method: F) where
116+
pub fn add_method_with_meta<F, I>(&mut self, name: &str, method: F)
117+
where
110118
F: Fn(&T, Params, M) -> I,
111119
I: IntoFuture<Item = Value, Error = Error>,
112120
F: Send + Sync + 'static,
113121
I::Future: Send + 'static,
114122
{
115-
self.methods.insert(name.into(), RemoteProcedure::Method(Arc::new(
116-
DelegateMethodWithMeta {
123+
self.methods.insert(
124+
name.into(),
125+
RemoteProcedure::Method(Arc::new(DelegateMethodWithMeta {
117126
delegate: self.delegate.clone(),
118127
closure: method,
119-
}
120-
)));
128+
})),
129+
);
121130
}
122131

123132
/// Adds notification to the delegate.
124-
pub fn add_notification<F>(&mut self, name: &str, notification: F) where
133+
pub fn add_notification<F>(&mut self, name: &str, notification: F)
134+
where
125135
F: Fn(&T, Params),
126136
F: Send + Sync + 'static,
127137
{
128-
self.methods.insert(name.into(), RemoteProcedure::Notification(Arc::new(
129-
DelegateNotification {
138+
self.methods.insert(
139+
name.into(),
140+
RemoteProcedure::Notification(Arc::new(DelegateNotification {
130141
delegate: self.delegate.clone(),
131142
closure: notification,
132-
}
133-
)));
143+
})),
144+
);
134145
}
135146
}
136147

137-
impl<T, M> Into<HashMap<String, RemoteProcedure<M>>> for IoDelegate<T, M> where
148+
impl<T, M> Into<HashMap<String, RemoteProcedure<M>>> for IoDelegate<T, M>
149+
where
138150
T: Send + Sync + 'static,
139151
M: Metadata,
140152
{

0 commit comments

Comments
 (0)