BREAKING CHANGE: improvement(lib): use u64 for Printer::display_offset and Squeezer::process, not usize

Technically a breaking change for architectures where
`size_of::<usize>() > size_of::<u64>()`, but that strikes me as
extremely unlikely.

This change is important because most file seek offsets, even on older
architectures with word sizes smaller than `u32`, accept a `u64`. In
particular, Rust's own `std` acknowledges this. So, we're actually going
against prior art in Rust by using a `usize`.
This commit is contained in:
Erich Gubler authored and David Peter committed 2020-06-07 11:08:01 +02:00
1 parent c5c8d1190f
commit 6d5c61b671
3 files changed
+22 -20

No files matched your search

+4 -4
View File
@@ -142,7 +142,7 @@ impl BorderStyle {
}
pub struct Printer<'a, Writer: Write> {
idx: usize,
idx: u64,
/// The raw bytes used as input for the current line.
raw_line: Vec<u8>,
/// The buffered line built with each byte, ready to print to writer.
@@ -154,7 +154,7 @@ pub struct Printer<'a, Writer: Write> {
byte_hex_table: Vec<String>,
byte_char_table: Vec<String>,
squeezer: Squeezer,
display_offset: usize,
display_offset: u64,
}
impl<'a, Writer: Write> Printer<'a, Writer> {
@@ -197,7 +197,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
}
}
pub fn display_offset(&mut self, display_offset: usize) -> &mut Self {
pub fn display_offset(&mut self, display_offset: u64) -> &mut Self {
self.display_offset = display_offset;
self
}
@@ -247,7 +247,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
}
let style = COLOR_OFFSET.normal();
let byte_index = format!("{:08x}", (self.idx - 1) + self.display_offset);
let byte_index = format!("{:08x}", self.idx - 1 + self.display_offset);
let formatted_string = if self.show_color {
format!("{}", style.paint(byte_index))
} else {