Skip to content

Commit d820df2

Browse files
committed
Minor non-breaking refactoring
1 parent 359ab71 commit d820df2

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

src/client/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ mod test {
6464
connection
6565
.send(resp_array!["PING", "TEST"])
6666
.map_err(|e| e.into())
67-
})
68-
.and_then(|connection| connection.take(1).collect());
67+
}).and_then(|connection| connection.take(1).collect());
6968

7069
let values = run_and_wait(connection).unwrap();
7170

@@ -89,12 +88,11 @@ mod test {
8988
.send_all(stream::iter_ok::<_, io::Error>(ops))
9089
.map(|(sender, _)| sender)
9190
.map_err(|e| e.into())
92-
})
93-
.and_then(|connection| connection.skip(1001).take(1).collect());
91+
}).and_then(|connection| connection.skip(1001).take(1).collect());
9492
let values = run_and_wait(connection).unwrap();
9593
assert_eq!(values.len(), 1);
9694
let values = match &values[0] {
97-
&resp::RespValue::Array(ref values) => values.clone(),
95+
resp::RespValue::Array(ref values) => values.clone(),
9896
_ => panic!("Not an array"),
9997
};
10098
assert_eq!(values.len(), 1000);

src/client/paired.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn paired_connect(
185185
// It ensures that a Tokio executor runs the future. This function would work correctly
186186
// without it, if we could be sure this function was only called by other futures that were
187187
// executed within the Tokio executor, but we cannot guarantee that.
188-
let addr = addr.clone();
188+
let addr = *addr;
189189
future::lazy(move || {
190190
reconnect(
191191
|con: &mpsc::UnboundedSender<SendPayload>, act| {
@@ -210,7 +210,7 @@ pub fn paired_connect(
210210
},
211211
)
212212
}).map(|out_tx_c| PairedConnection { out_tx_c })
213-
.map_err(|()| error::Error::EndOfStream)
213+
.map_err(|()| error::Error::EndOfStream)
214214
}
215215

216216
impl PairedConnection {
@@ -231,7 +231,7 @@ impl PairedConnection {
231231
T: resp::FromResp,
232232
{
233233
match &msg {
234-
&resp::RespValue::Array(_) => (),
234+
resp::RespValue::Array(_) => (),
235235
_ => {
236236
return Either::B(future::err(error::internal(
237237
"Command must be a RespValue::Array",

src/client/pubsub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub struct PubsubConnection {
216216
pub fn pubsub_connect(
217217
addr: &SocketAddr,
218218
) -> impl Future<Item = PubsubConnection, Error = error::Error> + Send {
219-
let addr = addr.clone();
219+
let addr = *addr;
220220
future::lazy(move || {
221221
reconnect(
222222
|con: &mpsc::UnboundedSender<PubsubEvent>, act| {
@@ -240,7 +240,7 @@ pub fn pubsub_connect(
240240
},
241241
)
242242
}).map(|out_tx_c| PubsubConnection { out_tx_c })
243-
.map_err(|()| error::Error::EndOfStream)
243+
.map_err(|()| error::Error::EndOfStream)
244244
}
245245

246246
impl PubsubConnection {

src/reconnect.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use std::error as std_error;
1212
use std::sync::{Arc, RwLock};
13-
use std::time::{Duration, Instant};
13+
use std::time::Duration;
1414

1515
use futures::{
1616
future::{self, Either},
@@ -19,7 +19,7 @@ use futures::{
1919
};
2020

2121
use tokio_executor::{DefaultExecutor, Executor};
22-
use tokio_timer::Deadline;
22+
use tokio_timer::Timeout;
2323

2424
#[derive(Debug)]
2525
pub(crate) enum ReconnectError {
@@ -125,9 +125,7 @@ where
125125

126126
let (tx, rx) = oneshot::channel();
127127

128-
let deadline = Instant::now() + Duration::from_secs(30); // TODO - review and make configurable
129-
130-
let connect_f = Deadline::new(connect_f, deadline).then(move |t| {
128+
let connect_f = Timeout::new(connect_f, Duration::from_secs(30)).then(move |t| {
131129
let mut state = reconnect.state.write().expect("Cannot obtain write lock");
132130
let result = match *state {
133131
NotConnected | Connecting => match t {

src/resp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum RespValue {
4646
}
4747

4848
impl RespValue {
49-
fn to_result(self) -> Result<RespValue, Error> {
49+
fn into_result(self) -> Result<RespValue, Error> {
5050
match self {
5151
RespValue::Error(string) => Err(Error::Remote(string)),
5252
x => Ok(x),
@@ -78,7 +78,7 @@ pub trait FromResp: Sized {
7878
/// Return a `Result` containing either `Self` or `Error`. Errors can occur due to either: a) the particular
7979
/// `RespValue` being incompatible with the required type, or b) a remote Redis error occuring.
8080
fn from_resp(resp: RespValue) -> Result<Self, Error> {
81-
Self::from_resp_int(resp.to_result()?)
81+
Self::from_resp_int(resp.into_result()?)
8282
}
8383

8484
fn from_resp_int(resp: RespValue) -> Result<Self, Error>;
@@ -442,7 +442,7 @@ fn parse_error(message: String) -> Error {
442442
/// two bytes will not be returned)
443443
///
444444
/// TODO - rename this function potentially, it's used for simple integers too
445-
fn scan_integer<'a>(buf: &'a mut BytesMut, idx: usize) -> Result<Option<(usize, &'a [u8])>, Error> {
445+
fn scan_integer(buf: &mut BytesMut, idx: usize) -> Result<Option<(usize, &[u8])>, Error> {
446446
let length = buf.len();
447447
let mut at_end = false;
448448
let mut pos = idx;
@@ -621,7 +621,7 @@ mod tests {
621621

622622
#[test]
623623
fn test_bulk_string() {
624-
let resp_object = RespValue::BulkString("THISISATEST".as_bytes().to_vec());
624+
let resp_object = RespValue::BulkString(b"THISISATEST".to_vec());
625625
let mut bytes = BytesMut::new();
626626
let mut codec = RespCodec;
627627
codec.encode(resp_object.clone(), &mut bytes).unwrap();

0 commit comments

Comments
 (0)