Skip to content

Commit d2d483a

Browse files
committed
Fix compiler and lint warnings/errors
1 parent 468b6e3 commit d2d483a

File tree

13 files changed

+30
-39
lines changed

13 files changed

+30
-39
lines changed

src/acl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl std::fmt::Display for Permission {
7676
.into_iter()
7777
.filter_map(|(perm, str)| if self.has(perm) { Some(str) } else { None })
7878
.enumerate()
79-
.try_for_each(|(i, str)| if i == 0 { f.write_str(str) } else { write!(f, "|{}", str) })
79+
.try_for_each(|(i, str)| if i == 0 { f.write_str(str) } else { write!(f, "|{str}") })
8080
}
8181
}
8282

src/client/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,11 @@ impl Client {
376376
fn parse_sequence(client_path: &str, prefix: &str) -> Result<CreateSequence> {
377377
if let Some(sequence_path) = client_path.strip_prefix(prefix) {
378378
match sequence_path.parse::<i64>() {
379-
Err(_) => Err(Error::UnexpectedError(format!("sequential node get no i32 path {}", client_path))),
379+
Err(_) => Err(Error::UnexpectedError(format!("sequential node get no i32 path {client_path}"))),
380380
Ok(i) => Ok(CreateSequence(i)),
381381
}
382382
} else {
383-
Err(Error::UnexpectedError(format!(
384-
"sequential path {} does not contain prefix path {}",
385-
client_path, prefix
386-
)))
383+
Err(Error::UnexpectedError(format!("sequential path {client_path} does not contain prefix path {prefix}",)))
387384
}
388385
}
389386

@@ -1049,7 +1046,7 @@ impl Client {
10491046
std::mem::forget(guard);
10501047
let prefix_len = prefix.len();
10511048
let mut path = prefix;
1052-
write!(&mut path, "{}", sequence).unwrap();
1049+
write!(&mut path, "{sequence}").unwrap();
10531050
let sequence_len = path.len() - prefix_len;
10541051
return Ok((path, sequence_len));
10551052
}

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Display for CustomError {
101101
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
102102
match (self.message.as_ref(), self.source.as_ref()) {
103103
(Some(message), None) => f.write_str(message),
104-
(Some(message), Some(err)) => write!(f, "{}: {}", message, err),
104+
(Some(message), Some(err)) => write!(f, "{message}: {err}"),
105105
(None, Some(err)) => err.fmt(f),
106106
_ => unreachable!("no error message or source"),
107107
}

src/proto/acl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl TryFrom<i32> for Permission {
3333
fn try_from(raw: i32) -> Result<Permission, Self::Error> {
3434
let all_bits = Permission::ALL.into_raw();
3535
if (raw & !all_bits) != 0 {
36-
return Err(InvalidData::UnmarshalError(format!("invalid permission bits: {:#b}", raw)));
36+
return Err(InvalidData::UnmarshalError(format!("invalid permission bits: {raw:#b}")));
3737
}
3838
Ok(Permission::from_raw(raw))
3939
}

src/proto/multi.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ impl DeserializableRecord<'_> for Vec<MultiReadResponse> {
8282
},
8383
op => {
8484
return Err(DeserializeError::UnmarshalError(format!(
85-
"unexpected op code {} in multi read response",
86-
op
85+
"unexpected op code {op} in multi read response"
8786
)))
8887
},
8988
}
@@ -136,8 +135,7 @@ impl<'a> DeserializableRecord<'a> for Vec<MultiWriteResponse<'a>> {
136135
},
137136
op => {
138137
return Err(DeserializeError::UnmarshalError(format!(
139-
"unexpected op code {} in multi write response",
140-
op
138+
"unexpected op code {op} in multi write response",
141139
)))
142140
},
143141
}

src/record.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ impl DeserializeError {
4242
pub fn with_entity(self, entity: &'static str) -> ZkError {
4343
match self {
4444
DeserializeError::InsufficientBuf => ZkError::UnmarshalError { entity, reason: &"insufficient buf" },
45-
DeserializeError::UnexpectedOpCode(code) => {
46-
ZkError::UnexpectedError(format!("unexpected op code {}", code))
47-
},
45+
DeserializeError::UnexpectedOpCode(code) => ZkError::UnexpectedError(format!("unexpected op code {code}")),
4846
DeserializeError::UnexpectedErrorCode(code) => ZkError::UnexpectedErrorCode(code),
4947
DeserializeError::UnmarshalError(err) => ZkError::UnexpectedError(err),
5048
}
@@ -284,7 +282,7 @@ impl UnsafeRead<'_> for bool {
284282
match buf.get_unchecked_u8() {
285283
0 => Ok(false),
286284
1 => Ok(true),
287-
u => Err(InvalidData::UnmarshalError(format!("invalid value {} for bool", u))),
285+
u => Err(InvalidData::UnmarshalError(format!("invalid value {u} for bool"))),
288286
}
289287
}
290288
}

src/sasl/mechanisms/digest_md5.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a> Parser<'a> {
8383
pub fn new(challenge: &'a [u8]) -> Result<Self, DigestError> {
8484
let challenge = match std::str::from_utf8(challenge) {
8585
Ok(s) => s,
86-
Err(err) => return Err(DigestError::new_parse(format!("support only utf8 for now: {}", err))),
86+
Err(err) => return Err(DigestError::new_parse(format!("support only utf8 for now: {err}"))),
8787
};
8888
Ok(Self { s: challenge })
8989
}
@@ -94,7 +94,7 @@ impl<'a> Parser<'a> {
9494
};
9595
self.skip_assignment();
9696
let Some((value, kind)) = self.read_value()? else {
97-
return Err(DigestError::new_parse(format!("directive {} has no value", key)));
97+
return Err(DigestError::new_parse(format!("directive {key} has no value")));
9898
};
9999
Ok(Some(Directive { key, value, kind }))
100100
}
@@ -116,7 +116,7 @@ impl<'a> Parser<'a> {
116116
self.skip_lws();
117117
if key.is_empty() {
118118
if !self.s.is_empty() {
119-
return Err(DigestError::new_parse(format!("no valid key from {}", s)));
119+
return Err(DigestError::new_parse(format!("no valid key from {s}")));
120120
}
121121
return Ok(None);
122122
}
@@ -377,7 +377,7 @@ impl DigestSession {
377377
fn gen_nonce() -> [u8; 32] {
378378
let r = fastrand::u128(0..u128::MAX);
379379
let mut buf = [0; 32];
380-
write!(buf.as_mut_slice(), "{:x}", r).unwrap();
380+
write!(buf.as_mut_slice(), "{r:x}").unwrap();
381381
buf
382382
}
383383
}
@@ -397,21 +397,21 @@ impl Authentication for DigestSession {
397397
None => return Err(DigestError::new_parse("no charset").into()),
398398
Some("utf-8") => true,
399399
Some(charset) => {
400-
return Err(DigestError::new_parse(format!("expect charset utf-8, but got {}", charset)).into())
400+
return Err(DigestError::new_parse(format!("expect charset utf-8, but got {charset}")).into())
401401
},
402402
};
403403
match directives.get_algorithm() {
404404
None => return Err(DigestError::new_parse("no algorithm").into()),
405405
Some("md5-sess") => {},
406406
Some(algorithm) => {
407407
return Err(
408-
DigestError::new_parse(format!("expect algorithm md5-sess, but got {}", algorithm)).into()
408+
DigestError::new_parse(format!("expect algorithm md5-sess, but got {algorithm}")).into()
409409
)
410410
},
411411
};
412412
if let Some(qop) = directives.get_qop() {
413413
if !qop.split(',').any(|s| s == "auth") {
414-
return Err(DigestError::new_protocol(format!("unsupported qop {}", qop)).into());
414+
return Err(DigestError::new_protocol(format!("unsupported qop {qop}")).into());
415415
}
416416
};
417417
let Some(nonce) = directives.get_nonce() else {
@@ -430,13 +430,12 @@ impl Authentication for DigestSession {
430430
*realm
431431
} else {
432432
return Err(DigestError::new_protocol(format!(
433-
"can not choose realm {} from {:?}",
434-
client_realm, realms
433+
"can not choose realm {client_realm} from {realms:?}",
435434
))
436435
.into());
437436
}
438437
} else {
439-
return Err(DigestError::new_protocol(format!("choose no realm from {:?}", realms)).into());
438+
return Err(DigestError::new_protocol(format!("choose no realm from {realms:?}")).into());
440439
};
441440
let username = session.need_with::<AuthId, _, _>(&EmptyProvider, |auth_id| Ok(auth_id.to_string()))?;
442441
let password =
@@ -451,8 +450,7 @@ impl Authentication for DigestSession {
451450
};
452451
let response = context.client_response();
453452
write!(writer,
454-
r#"username="{}",realm="{}",nonce="{}",cnonce="{}",nc=00000001,qop=auth,digest-uri="zookeeper/zk-sasl-md5",response={},charset="utf-8""#,
455-
username, realm, nonce,
453+
r#"username="{username}",realm="{realm}",nonce="{nonce}",cnonce="{}",nc=00000001,qop=auth,digest-uri="zookeeper/zk-sasl-md5",response={},charset="utf-8""#,
456454
unsafe { std::str::from_utf8_unchecked(cnonce.as_slice()) },
457455
unsafe { std::str::from_utf8_unchecked(response.as_slice()) },
458456
).unwrap();

src/session/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::endpoint::{EndpointRef, IterableEndpoints};
3232
pub enum Connection {
3333
Raw(TcpStream),
3434
#[cfg(feature = "tls")]
35-
Tls(TlsStream<TcpStream>),
35+
Tls(Box<TlsStream<TcpStream>>),
3636
}
3737

3838
pub trait AsyncReadToBuf: AsyncReadExt {
@@ -143,7 +143,7 @@ impl Connection {
143143

144144
#[cfg(feature = "tls")]
145145
pub fn new_tls(stream: TlsStream<TcpStream>) -> Self {
146-
Self::Tls(stream)
146+
Self::Tls(stream.into())
147147
}
148148

149149
pub async fn command(mut self, cmd: &str) -> Result<String> {

src/session/depot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Depot {
101101

102102
pub fn pop_request(&mut self, xid: i32) -> Result<SessionOperation, Error> {
103103
match self.written_operations.remove(&xid) {
104-
None => Err(Error::UnexpectedError(format!("recv response with xid {} but no pending request", xid))),
104+
None => Err(Error::UnexpectedError(format!("recv response with xid {xid} but no pending request"))),
105105
Some(operation) => Ok(operation),
106106
}
107107
}

src/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ impl Session {
563563
select! {
564564
Some(endpoint) = Self::poll(&mut seek_for_writable), if seek_for_writable.is_some() => {
565565
seek_for_writable = None;
566-
err = Some(Error::with_message(format!("encounter writable server {}", endpoint)));
566+
err = Some(Error::with_message(format!("encounter writable server {endpoint}")));
567567
channel_halted = true;
568568
},
569569
r = reader.read_to_buf(buf) => match r.map_err(Error::other)? {

0 commit comments

Comments
 (0)