Skip to content

Commit e7af332

Browse files
committed
chore: fix clippy errors and set msrv to 1.63
1 parent 84f4f60 commit e7af332

File tree

7 files changed

+29
-37
lines changed

7 files changed

+29
-37
lines changed

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msrv="1.63.0"

src/batch.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::types::{Call, Param, ToElectrumScriptHash};
1616
/// [`Client`](../client/struct.Client.html), like
1717
/// [`batch_script_get_balance`](../client/struct.Client.html#method.batch_script_get_balance) to ask the
1818
/// server for the balance of multiple scripts with a single request.
19+
#[derive(Default)]
1920
pub struct Batch {
2021
calls: Vec<Call>,
2122
}
@@ -107,9 +108,3 @@ impl<'a> std::iter::Iterator for BatchIter<'a> {
107108
val
108109
}
109110
}
110-
111-
impl std::default::Default for Batch {
112-
fn default() -> Self {
113-
Batch { calls: Vec::new() }
114-
}
115-
}

src/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mod tests {
353353
fn more_failed_attempts_than_retries_means_exhausted() {
354354
let exhausted = retries_exhausted(10, 5);
355355

356-
assert_eq!(exhausted, true)
356+
assert!(exhausted)
357357
}
358358

359359
#[test]
@@ -362,21 +362,21 @@ mod tests {
362362

363363
let exhausted = retries_exhausted(failed_attempts, u8::MAX);
364364

365-
assert_eq!(exhausted, true)
365+
assert!(exhausted)
366366
}
367367

368368
#[test]
369369
fn less_failed_attempts_means_not_exhausted() {
370370
let exhausted = retries_exhausted(2, 5);
371371

372-
assert_eq!(exhausted, false)
372+
assert!(!exhausted)
373373
}
374374

375375
#[test]
376376
fn attempts_equals_retries_means_not_exhausted_yet() {
377377
let exhausted = retries_exhausted(2, 2);
378378

379-
assert_eq!(exhausted, false)
379+
assert!(!exhausted)
380380
}
381381

382382
#[test]
@@ -408,7 +408,7 @@ mod tests {
408408
sender.send(()).unwrap();
409409

410410
for _stream in listener.incoming() {
411-
loop {}
411+
std::thread::sleep(Duration::from_secs(60))
412412
}
413413
});
414414

src/raw_client.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub trait ToSocketAddrsDomain: ToSocketAddrs {
8383

8484
impl ToSocketAddrsDomain for &str {
8585
fn domain(&self) -> Option<&str> {
86-
self.splitn(2, ':').next()
86+
self.split(':').next()
8787
}
8888
}
8989

@@ -406,11 +406,11 @@ impl RawClient<ElectrumSslStream> {
406406
socket_addr.domain().ok_or(Error::MissingDomain)?;
407407

408408
let store = webpki_roots::TLS_SERVER_ROOTS
409-
.into_iter()
409+
.iter()
410410
.map(|t| TrustAnchor {
411411
subject: Der::from_slice(t.subject),
412412
subject_public_key_info: Der::from_slice(t.spki),
413-
name_constraints: t.name_constraints.map(|nc| Der::from_slice(nc)),
413+
name_constraints: t.name_constraints.map(Der::from_slice),
414414
})
415415
.collect::<RootCertStore>();
416416

@@ -605,7 +605,7 @@ impl<S: Read + Write> RawClient<S> {
605605
// No id, that's probably a notification.
606606
let mut resp = resp;
607607

608-
if let Some(ref method) = resp["method"].take().as_str() {
608+
if let Some(method) = resp["method"].take().as_str() {
609609
self.handle_notification(method, resp["params"].take())?;
610610
} else {
611611
warn!("Unexpected response: {:?}", resp);
@@ -722,7 +722,7 @@ impl<S: Read + Write> RawClient<S> {
722722
) -> Result<serde_json::Value, Error> {
723723
let req = Request::new_id(
724724
self.last_id.fetch_add(1, Ordering::SeqCst),
725-
&method_name,
725+
method_name,
726726
params,
727727
);
728728
let result = self.call(req)?;
@@ -763,7 +763,7 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
763763
for (method, params) in batch.iter() {
764764
let req = Request::new_id(
765765
self.last_id.fetch_add(1, Ordering::SeqCst),
766-
&method,
766+
method,
767767
params.to_vec(),
768768
);
769769
missing_responses.insert(req.id);
@@ -804,7 +804,7 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
804804
};
805805
}
806806

807-
Ok(answers.into_iter().map(|(_, r)| r).collect())
807+
Ok(answers.into_values().collect())
808808
}
809809

810810
fn block_headers_subscribe_raw(&self) -> Result<RawHeaderNotification, Error> {
@@ -1128,7 +1128,7 @@ mod test {
11281128
use crate::utils;
11291129

11301130
use super::RawClient;
1131-
use api::ElectrumApi;
1131+
use crate::api::ElectrumApi;
11321132

11331133
fn get_test_server() -> String {
11341134
std::env::var("TEST_ELECTRUM_SERVER").unwrap_or("electrum.blockstream.info:50001".into())
@@ -1426,7 +1426,7 @@ mod test {
14261426

14271427
#[test]
14281428
fn test_raw_call() {
1429-
use types::Param;
1429+
use crate::types::Param;
14301430

14311431
let client = RawClient::new(get_test_server(), None).unwrap();
14321432

src/socks/v4.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Socks4Stream {
109109
let _ = packet.write_u32::<BigEndian>(Ipv4Addr::new(0, 0, 0, 1).into());
110110
let _ = packet.write_all(userid.as_bytes());
111111
let _ = packet.write_u8(0);
112-
let _ = packet.extend(host.as_bytes());
112+
packet.extend(host.as_bytes());
113113
let _ = packet.write_u8(0);
114114
}
115115
}
@@ -118,8 +118,8 @@ impl Socks4Stream {
118118
let proxy_addr = read_response(&mut socket)?;
119119

120120
Ok(Socks4Stream {
121-
socket: socket,
122-
proxy_addr: proxy_addr,
121+
socket,
122+
proxy_addr,
123123
})
124124
}
125125

src/socks/v5.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn write_addr(mut packet: &mut [u8], target: &TargetAddr) -> io::Result<usize> {
110110
}
111111
TargetAddr::Domain(ref domain, port) => {
112112
packet.write_u8(3).unwrap();
113-
if domain.len() > u8::max_value() as usize {
113+
if domain.len() > u8::MAX as usize {
114114
return Err(io::Error::new(
115115
io::ErrorKind::InvalidInput,
116116
"domain name too long",
@@ -144,11 +144,7 @@ impl<'a> Authentication<'a> {
144144
}
145145

146146
fn is_no_auth(&self) -> bool {
147-
if let Authentication::None = *self {
148-
true
149-
} else {
150-
false
151-
}
147+
matches!(*self, Authentication::None)
152148
}
153149
}
154150

@@ -258,8 +254,8 @@ impl Socks5Stream {
258254
let proxy_addr = read_response(&mut socket)?;
259255

260256
Ok(Socks5Stream {
261-
socket: socket,
262-
proxy_addr: proxy_addr,
257+
socket,
258+
proxy_addr,
263259
})
264260
}
265261

@@ -268,13 +264,13 @@ impl Socks5Stream {
268264
username: &str,
269265
password: &str,
270266
) -> io::Result<()> {
271-
if username.len() < 1 || username.len() > 255 {
267+
if username.is_empty() || username.len() > 255 {
272268
return Err(io::Error::new(
273269
io::ErrorKind::InvalidInput,
274270
"invalid username",
275271
));
276272
};
277-
if password.len() < 1 || password.len() > 255 {
273+
if password.is_empty() || password.len() > 255 {
278274
return Err(io::Error::new(
279275
io::ErrorKind::InvalidInput,
280276
"invalid password",
@@ -475,8 +471,8 @@ impl Socks5Datagram {
475471
socket.connect(&stream.proxy_addr)?;
476472

477473
Ok(Socks5Datagram {
478-
socket: socket,
479-
stream: stream,
474+
socket,
475+
stream,
480476
})
481477
}
482478

@@ -528,7 +524,7 @@ impl Socks5Datagram {
528524
unsafe {
529525
ptr::copy(
530526
buf.as_ptr(),
531-
buf.as_mut_ptr().offset(header.len() as isize),
527+
buf.as_mut_ptr().add(header.len()),
532528
overflow,
533529
);
534530
}

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl From<[u8; 32]> for Hex32Bytes {
8787
}
8888

8989
impl Hex32Bytes {
90-
pub(crate) fn to_hex(&self) -> String {
90+
pub(crate) fn to_hex(self) -> String {
9191
self.0.to_lower_hex_string()
9292
}
9393
}

0 commit comments

Comments
 (0)