Skip to content

Commit

Permalink
Clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Jan 9, 2025
1 parent 6d97c05 commit 5d264bf
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 217 deletions.
406 changes: 205 additions & 201 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bin/ion/commands/generate/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> CodeGenerator<'a, JavaLanguage> {
}
}

impl<'a, L: Language + 'static> CodeGenerator<'a, L> {
impl<L: Language + 'static> CodeGenerator<'_, L> {
/// A [tera] filter that converts given tera string value to [upper camel case].
/// Returns error if the given value is not a string.
///
Expand Down
11 changes: 9 additions & 2 deletions src/bin/ion/commands/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ion_rs::ion_hash::IonHasher;
use ion_rs::*;
use sha2::{Sha256, Sha512};
use sha3::{Sha3_256, Sha3_512};
use std::fmt;
use std::io::Write;

// Macro to eliminate repetitive code for each hash algorithm.
Expand Down Expand Up @@ -109,8 +110,14 @@ impl IonCliCommand for HashCommand {
for elem in reader.elements() {
let elem = elem?;
let digest = hasher.hash_it(&elem)?;
let digest_string: String =
digest.iter().map(|b| format!("{:02x?}", b)).collect();
let digest_string = digest.iter().fold(
String::with_capacity(digest.len() * 2),
|mut string, byte| {
use fmt::Write;
write!(&mut string, "{:02x}", byte).expect("infallible");
string
},
);
output.write_all(digest_string.as_bytes())?;
output.write_all("\n".as_bytes())?;
}
Expand Down
6 changes: 4 additions & 2 deletions src/bin/ion/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ impl<'a, 'b> IonInspector<'a, 'b> {
)
}

#[allow(clippy::too_many_arguments)]
fn inspect_literal_sequence<'x, D: Decoder>(
&mut self,
depth: usize,
Expand All @@ -1059,6 +1060,7 @@ impl<'a, 'b> IonInspector<'a, 'b> {
)
}

#[allow(clippy::too_many_arguments)]
fn inspect_ephemeral_sequence<'x>(
&mut self,
depth: usize,
Expand Down Expand Up @@ -1253,7 +1255,7 @@ impl<'a, 'b> IonInspector<'a, 'b> {
self.inspect_literal_container_footer(depth, encoded_value, "}", trailing_delimiter)
}

fn inspect_ephemeral_struct<'x>(
fn inspect_ephemeral_struct(
&mut self,
depth: usize,
delimiter: &str,
Expand All @@ -1276,7 +1278,7 @@ impl<'a, 'b> IonInspector<'a, 'b> {
})
}

fn inspect_struct_body<'x>(
fn inspect_struct_body(
&mut self,
depth: usize,
struct_: LazyStruct<AnyEncoding>,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ion/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub struct CommandIo<'a> {
args: &'a ArgMatches,
}

impl<'a> CommandIo<'a> {
impl CommandIo<'_> {
fn new(args: &ArgMatches) -> CommandIo {
CommandIo { args }
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ion/commands/schema/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ fn write_validation_result_ion<W: ValueWriter>(
}

/// Transposes a borrowed vec of owned elements into an owned vec of borrowed elements.
fn vec_of_refs(the_vec: &Vec<Element>) -> Vec<&Element> {
fn vec_of_refs(the_vec: &[Element]) -> Vec<&Element> {
the_vec.iter().collect()
}
2 changes: 1 addition & 1 deletion src/bin/ion/commands/symtab/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn filter_out_user_data(
// or
// $ion_symbol_table::{}$ion_1_0$ion_symbol_table::{}
if reader.detected_encoding().is_text() {
output.write_all(&[b'\n']).unwrap()
output.write_all(b"\n").unwrap()
}
}
}
12 changes: 6 additions & 6 deletions src/bin/ion/hex_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ impl<R: Read> From<R> for HexReader<R> {

impl<R: Read> Read for HexReader<R> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
if buf.len() == 0 {
if buf.is_empty() {
return Ok(0);
}

let mut bytes_read = 0usize;

while let Some(b) = self.inner.next() {
let c = char::from(b?);
for byte in &mut self.inner {
let c = char::from(byte?);

use DigitState::*;
match self.digit_state {
Expand All @@ -67,9 +67,9 @@ impl<R: Read> Read for HexReader<R> {
// Now we know that this hex-encoded byte is going to be `0xHH` rather than `0H`
Zero if c == 'x' => self.digit_state = ZeroX,
// Reading the first digit of the hex-encoded byte
Empty | ZeroX if c.is_digit(16) => self.digit_state = HasUpperNibble(c),
Empty | ZeroX if c.is_ascii_hexdigit() => self.digit_state = HasUpperNibble(c),
// Reading the second digit of the hex-encoded byte
Zero if c.is_digit(16) => {
Zero if c.is_ascii_hexdigit() => {
// Unwrap is guaranteed not to panic because we've been putting only valid hex
// digit characters in the `digit_buffer` String.
let value = c.to_digit(16).unwrap();
Expand All @@ -78,7 +78,7 @@ impl<R: Read> Read for HexReader<R> {
bytes_read += 1;
self.digit_state = Empty;
}
HasUpperNibble(c0) if c.is_digit(16) => {
HasUpperNibble(c0) if c.is_ascii_hexdigit() => {
// The first unwrap is guaranteed not to panic because we already know that both
// chars are valid hex digits.
// The second unwrap is guaranteed not to panic because the max it could be is 0x0F
Expand Down
4 changes: 2 additions & 2 deletions src/bin/ion/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum CommandOutput<'a> {
File(FileWriter),
}

impl<'a> Write for CommandOutput<'a> {
impl Write for CommandOutput<'_> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
use CommandOutput::*;
match self {
Expand All @@ -27,7 +27,7 @@ impl<'a> Write for CommandOutput<'a> {
}
}

impl<'a> WriteColor for CommandOutput<'a> {
impl WriteColor for CommandOutput<'_> {
fn supports_color(&self) -> bool {
use CommandOutput::*;
match self {
Expand Down

0 comments on commit 5d264bf

Please sign in to comment.