Skip to content

Commit 38301f3

Browse files
committed
Fix clippy, CI
1 parent f2547ae commit 38301f3

File tree

5 files changed

+96
-131
lines changed

5 files changed

+96
-131
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ readme = "README.md"
99
repository = "https://github.com/sharkdp/hexyl"
1010
version = "0.16.0"
1111
edition = "2021"
12-
rust-version = "1.80"
12+
rust-version = "1.88"
1313

1414
[dependencies]
1515
anyhow = "1.0"

examples/simple.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use std::io;
33
use hexyl::{BorderStyle, PrinterBuilder};
44

55
fn main() {
6-
let input = vec![
7-
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44,
8-
0x52, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x44, 0x08, 0x02, 0x00, 0x00, 0x00,
9-
];
6+
let input = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44,
7+
0x52, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x44, 0x08, 0x02, 0x00, 0x00, 0x00];
108

119
let stdout = io::stdout();
1210
let mut handle = stdout.lock();

src/colors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub const COLOR_RESET: &str = colors::Default::ANSI_FG;
1818

1919
fn init_color(name: &str, default_ansi: AnsiColors) -> String {
2020
let default = DynColors::Ansi(default_ansi);
21-
let env_var = format!("HEXYL_COLOR_{}", name);
21+
let env_var = format!("HEXYL_COLOR_{name}");
2222
let color = match std::env::var(env_var).as_deref() {
2323
Ok(color) => match DynColors::from_str(color) {
2424
Ok(color) => color,

src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Seek for Input<'_> {
2121
where
2222
R: Read,
2323
{
24-
let cant_seek_abs_err = || Err(io::Error::new(io::ErrorKind::Other, err_desc));
24+
let cant_seek_abs_err = || Err(io::Error::other(err_desc));
2525

2626
let offset = match pos {
2727
SeekFrom::Current(o) => u64::try_from(o).or_else(|_e| cant_seek_abs_err())?,

src/lib.rs

Lines changed: 91 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,45 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> {
344344
}
345345

346346
pub fn build(self) -> Printer<'a, Writer> {
347-
Printer::new(
348-
self.writer,
349-
self.show_color,
350-
self.show_char_panel,
351-
self.show_position_panel,
352-
self.border_style,
353-
self.use_squeeze,
354-
self.panels,
355-
self.group_size,
356-
self.base,
357-
self.endianness,
358-
self.character_table,
359-
self.color_scheme,
360-
)
347+
Printer {
348+
idx: 0,
349+
line_buf: vec![0x0; 8 * self.panels as usize],
350+
writer: self.writer,
351+
show_char_panel: self.show_char_panel,
352+
show_position_panel: self.show_position_panel,
353+
show_color: self.show_color,
354+
curr_color: None,
355+
color_scheme: self.color_scheme,
356+
border_style: self.border_style,
357+
byte_hex_panel: (0u8..=u8::MAX)
358+
.map(|i| match self.base {
359+
Base::Binary => format!("{i:08b}"),
360+
Base::Octal => format!("{i:03o}"),
361+
Base::Decimal => format!("{i:03}"),
362+
Base::Hexadecimal => format!("{i:02x}"),
363+
})
364+
.collect(),
365+
byte_char_panel: (0u8..=u8::MAX)
366+
.map(|i| format!("{}", Byte(i).as_char(self.character_table)))
367+
.collect(),
368+
byte_hex_panel_g: (0u8..=u8::MAX).map(|i| format!("{i:02x}")).collect(),
369+
squeezer: if self.use_squeeze {
370+
Squeezer::Ignore
371+
} else {
372+
Squeezer::Disabled
373+
},
374+
display_offset: 0,
375+
panels: self.panels,
376+
squeeze_byte: 0x00,
377+
group_size: self.group_size,
378+
base_digits: match self.base {
379+
Base::Binary => 8,
380+
Base::Octal => 3,
381+
Base::Decimal => 3,
382+
Base::Hexadecimal => 2,
383+
},
384+
endianness: self.endianness,
385+
}
361386
}
362387
}
363388

@@ -390,60 +415,6 @@ pub struct Printer<'a, Writer: Write> {
390415
}
391416

392417
impl<'a, Writer: Write> Printer<'a, Writer> {
393-
fn new(
394-
writer: &'a mut Writer,
395-
show_color: bool,
396-
show_char_panel: bool,
397-
show_position_panel: bool,
398-
border_style: BorderStyle,
399-
use_squeeze: bool,
400-
panels: u64,
401-
group_size: u8,
402-
base: Base,
403-
endianness: Endianness,
404-
character_table: CharacterTable,
405-
color_scheme: ColorScheme,
406-
) -> Printer<'a, Writer> {
407-
Printer {
408-
idx: 0,
409-
line_buf: vec![0x0; 8 * panels as usize],
410-
writer,
411-
show_char_panel,
412-
show_position_panel,
413-
show_color,
414-
curr_color: None,
415-
color_scheme,
416-
border_style,
417-
byte_hex_panel: (0u8..=u8::MAX)
418-
.map(|i| match base {
419-
Base::Binary => format!("{i:08b}"),
420-
Base::Octal => format!("{i:03o}"),
421-
Base::Decimal => format!("{i:03}"),
422-
Base::Hexadecimal => format!("{i:02x}"),
423-
})
424-
.collect(),
425-
byte_char_panel: (0u8..=u8::MAX)
426-
.map(|i| format!("{}", Byte(i).as_char(character_table)))
427-
.collect(),
428-
byte_hex_panel_g: (0u8..=u8::MAX).map(|i| format!("{i:02x}")).collect(),
429-
squeezer: if use_squeeze {
430-
Squeezer::Ignore
431-
} else {
432-
Squeezer::Disabled
433-
},
434-
display_offset: 0,
435-
panels,
436-
squeeze_byte: 0x00,
437-
group_size,
438-
base_digits: match base {
439-
Base::Binary => 8,
440-
Base::Octal => 3,
441-
Base::Decimal => 3,
442-
Base::Hexadecimal => 2,
443-
},
444-
endianness,
445-
}
446-
}
447418

448419
pub fn display_offset(&mut self, display_offset: u64) -> &mut Self {
449420
self.display_offset = display_offset;
@@ -844,20 +815,19 @@ mod tests {
844815

845816
fn assert_print_all_output<Reader: Read>(input: Reader, expected_string: String) {
846817
let mut output = vec![];
847-
let mut printer = Printer::new(
848-
&mut output,
849-
false,
850-
true,
851-
true,
852-
BorderStyle::Unicode,
853-
true,
854-
2,
855-
1,
856-
Base::Hexadecimal,
857-
Endianness::Big,
858-
CharacterTable::Default,
859-
ColorScheme::Default,
860-
);
818+
let mut printer = PrinterBuilder::new(&mut output)
819+
.show_color(false)
820+
.show_char_panel(true)
821+
.show_position_panel(true)
822+
.with_border_style(BorderStyle::Unicode)
823+
.enable_squeezing(true)
824+
.num_panels(2)
825+
.group_size(1)
826+
.with_base(Base::Hexadecimal)
827+
.endianness(Endianness::Big)
828+
.character_table(CharacterTable::Default)
829+
.color_scheme(ColorScheme::Default)
830+
.build();
861831

862832
printer.print_all(input).unwrap();
863833

@@ -901,20 +871,19 @@ mod tests {
901871
.to_owned();
902872

903873
let mut output = vec![];
904-
let mut printer: Printer<Vec<u8>> = Printer::new(
905-
&mut output,
906-
false,
907-
true,
908-
true,
909-
BorderStyle::Unicode,
910-
true,
911-
2,
912-
1,
913-
Base::Hexadecimal,
914-
Endianness::Big,
915-
CharacterTable::Default,
916-
ColorScheme::Default,
917-
);
874+
let mut printer: Printer<Vec<u8>> = PrinterBuilder::new(&mut output)
875+
.show_color(false)
876+
.show_char_panel(true)
877+
.show_position_panel(true)
878+
.with_border_style(BorderStyle::Unicode)
879+
.enable_squeezing(true)
880+
.num_panels(2)
881+
.group_size(1)
882+
.with_base(Base::Hexadecimal)
883+
.endianness(Endianness::Big)
884+
.character_table(CharacterTable::Default)
885+
.color_scheme(ColorScheme::Default)
886+
.build();
918887
printer.display_offset(0xdeadbeef);
919888

920889
printer.print_all(input).unwrap();
@@ -937,20 +906,19 @@ mod tests {
937906
.to_owned();
938907

939908
let mut output = vec![];
940-
let mut printer: Printer<Vec<u8>> = Printer::new(
941-
&mut output,
942-
false,
943-
true,
944-
true,
945-
BorderStyle::Unicode,
946-
true,
947-
4,
948-
1,
949-
Base::Hexadecimal,
950-
Endianness::Big,
951-
CharacterTable::Default,
952-
ColorScheme::Default,
953-
);
909+
let mut printer: Printer<Vec<u8>> = PrinterBuilder::new(&mut output)
910+
.show_color(false)
911+
.show_char_panel(true)
912+
.show_position_panel(true)
913+
.with_border_style(BorderStyle::Unicode)
914+
.enable_squeezing(true)
915+
.num_panels(4)
916+
.group_size(1)
917+
.with_base(Base::Hexadecimal)
918+
.endianness(Endianness::Big)
919+
.character_table(CharacterTable::Default)
920+
.color_scheme(ColorScheme::Default)
921+
.build();
954922

955923
printer.print_all(input).unwrap();
956924

@@ -999,20 +967,19 @@ mod tests {
999967
.to_owned();
1000968

1001969
let mut output = vec![];
1002-
let mut printer: Printer<Vec<u8>> = Printer::new(
1003-
&mut output,
1004-
false,
1005-
true,
1006-
true,
1007-
BorderStyle::Unicode,
1008-
true,
1009-
3,
1010-
1,
1011-
Base::Hexadecimal,
1012-
Endianness::Big,
1013-
CharacterTable::Default,
1014-
ColorScheme::Default,
1015-
);
970+
let mut printer: Printer<Vec<u8>> = PrinterBuilder::new(&mut output)
971+
.show_color(false)
972+
.show_char_panel(true)
973+
.show_position_panel(true)
974+
.with_border_style(BorderStyle::Unicode)
975+
.enable_squeezing(true)
976+
.num_panels(3)
977+
.group_size(1)
978+
.with_base(Base::Hexadecimal)
979+
.endianness(Endianness::Big)
980+
.character_table(CharacterTable::Default)
981+
.color_scheme(ColorScheme::Default)
982+
.build();
1016983

1017984
printer.print_all(input).unwrap();
1018985

0 commit comments

Comments
 (0)