Skip to content

Commit

Permalink
refactor: eliminate indexing and slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Dec 5, 2024
1 parent 7ce8bf0 commit 3fef815
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ impl ClientCodec {
}
if self.escape_count == 3 {
self.escape_count = 0;
buf.write_all(&frame[start..idx]).await?;
buf.write_all(frame.get(start..idx).unwrap_or_default())
.await?;
buf.write_all(b".").await?;
start = idx;
}
}
buf.write_all(&frame[start..]).await?;
buf.write_all(frame.get(start..).unwrap_or_default())
.await?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ServerInfo {
features.insert(Extension::StartTls);
}
Some("AUTH") => {
for &mechanism in &split[1..] {
for &mechanism in split.iter().skip(1) {
match mechanism {
"PLAIN" => {
features.insert(Extension::Authentication(Mechanism::Plain));
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
unused_import_braces,
missing_debug_implementations,
missing_docs,
clippy::explicit_iter_loop
clippy::explicit_iter_loop,
clippy::unwrap_used,
clippy::expect_used,
clippy::indexing_slicing,
clippy::string_slice
)]

#[cfg(not(any(feature = "runtime-tokio", feature = "runtime-async-std")))]
Expand Down
18 changes: 5 additions & 13 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,14 @@ pub struct XText<'a>(pub &'a str);

impl Display for XText<'_> {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
let mut rest = self.0;
while let Some(idx) = rest.find(|c| c < '!' || c == '+' || c == '=') {
let (start, end) = rest.split_at(idx);
f.write_str(start)?;

let mut end_iter = end.char_indices();
let (_, c) = end_iter.next().expect("char");
write!(f, "+{:X}", c as u8)?;

if let Some((idx, _)) = end_iter.next() {
rest = &end[idx..];
for c in self.0.chars() {
if c < '!' || c == '+' || c == '=' {
write!(f, "+{:X}", c as u8)?;
} else {
rest = "";
write!(f, "{c}")?;
}
}
f.write_str(rest)
Ok(())
}
}

Expand Down

0 comments on commit 3fef815

Please sign in to comment.