Skip to content

Commit 27d0643

Browse files
committed
Take transport by reference, get rid of clone bound
1 parent 05d25f0 commit 27d0643

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

core/src/lib.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<T> Future for RpcRequest<T> {
126126

127127
/// Trait for types acting as a transport layer for the JSON-RPC 2.0 clients generated by the
128128
/// `jsonrpc_client` macro.
129-
pub trait Transport: Clone + Send + 'static {
129+
pub trait Transport {
130130
/// The type of error that this transport emits if it fails.
131131
type Error: ::std::error::Error + Send + 'static;
132132

@@ -147,7 +147,7 @@ pub trait Transport: Clone + Send + 'static {
147147
/// # Not intended for direct use
148148
/// This is being called from the client structs generated by the `jsonrpc_client` macro. This
149149
/// function is not intended to be used directly, only the generated structs should call this.
150-
pub fn call_method<T, P, R>(mut transport: T, method: String, params: P) -> RpcRequest<R>
150+
pub fn call_method<T, P, R>(transport: &mut T, method: String, params: P) -> RpcRequest<R>
151151
where
152152
T: Transport,
153153
P: serde::Serialize,
@@ -160,31 +160,30 @@ where
160160
method,
161161
raw_id
162162
);
163-
let request = serialize_request(id.clone(), method.clone(), params)
163+
let request_serialization_result = serialize_request(id.clone(), method.clone(), params)
164164
.chain_err(|| ErrorKind::SerializeError);
165-
let method_copy1 = method.clone();
166-
let method_copy2 = method.clone();
167-
168-
let future = futures::future::result(request)
169-
.and_then(move |request_raw| {
165+
match request_serialization_result {
166+
Err(e) => RpcRequest(Box::new(futures::future::err(e))),
167+
Ok(request_raw) => {
170168
trace!(
171169
"Sending call to method \"{}\" with id {} to transport",
172-
method_copy1,
170+
method,
173171
raw_id
174172
);
175-
transport
173+
let future = transport
176174
.send(request_raw)
177175
.map_err(|e| Error::with_chain(e, ErrorKind::TransportError))
178-
})
179-
.and_then(move |response_raw: Vec<u8>| {
180-
trace!(
181-
"Deserializing response to method \"{}\" with id {}",
182-
method_copy2,
183-
raw_id
184-
);
185-
response::parse::<R>(&response_raw, id)
186-
});
187-
RpcRequest(Box::new(future))
176+
.and_then(move |response_raw: Vec<u8>| {
177+
trace!(
178+
"Deserializing response to method \"{}\" with id {}",
179+
method,
180+
raw_id
181+
);
182+
response::parse::<R>(&response_raw, id)
183+
});
184+
RpcRequest(Box::new(future))
185+
}
186+
}
188187
}
189188

190189

core/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ macro_rules! jsonrpc_client {
3636
{
3737
let method = String::from(stringify!($method));
3838
let params = expand_params!($($arg_name,)*);
39-
$crate::call_method($selff.transport.clone(), method, params)
39+
$crate::call_method(&mut $selff.transport, method, params)
4040
}
4141
)*
4242
}

0 commit comments

Comments
 (0)