Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Remove the remaining casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Apr 23, 2019
1 parent a121d18 commit e798b1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/byte_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TilingByteReader {
// The 'h' height is the number of lines in the window,
// and 'w' is the width of each window line.
let (x, y, w, h) = window;
let mut read_buf = vec![0; w as usize];
let mut read_buf = vec![0; usize::from(w)];

for i in y..(y + (u64::from(h))) {
let offset = line_length * i + x;
Expand Down
48 changes: 28 additions & 20 deletions src/hex_reader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::convert::TryFrom;
use std::io::Result;
use std::path::PathBuf;

use crate::byte_reader::TilingByteReader;
use crate::hex_tables::*;
use std::path::PathBuf;

#[derive(Copy, Clone, Debug)]
pub enum VisualMode {
Expand Down Expand Up @@ -95,21 +96,22 @@ impl HexReader {
}

pub fn visit_row_offsets(&self, visitor: &mut OffsetsVisitor) {
let (w, h) = self.window_size;
let w = usize::from(self.window_size.0);
let h = usize::from(self.window_size.1);
let base_offset = self.window_pos.1 * self.line_width;
let mut capture_height = self.capture.len() / w as usize;
if capture_height * (w as usize) < self.capture.len() {
let mut capture_height = self.capture.len() / w;
if capture_height * w < self.capture.len() {
capture_height += 1;
}
let height = (h as usize).min(capture_height);
let height = u64::try_from(h.min(capture_height)).unwrap();

if self.reader.use_large_addresses() {
for i in 0..height as u64 {
for i in 0..height {
let offset = base_offset + i * self.line_width;
visitor.offset(&format!("0x{:016X}", offset));
}
} else {
for i in 0..height as u64 {
for i in 0..height {
let offset = base_offset + i * self.line_width;
visitor.offset(&format!("0x{:08X}", offset));
}
Expand All @@ -118,18 +120,20 @@ impl HexReader {
}

pub fn visit_hex(&self, visitor: &mut HexVisitor) {
let cap = self.capture.as_slice();

let capture = self.capture.as_slice();
let line_cap = u64::from(self.window_size.0);
let group = u64::from(self.group);

let mut i = 0;
for b in cap {
for b in capture {
i += 1;
let r = *b as usize;
let r = usize::from(*b);
visitor.byte(r);
if i == self.window_size.0 {

if i == line_cap {
visitor.next_line();
i = 0;
} else if (self.window_pos.0 + u64::from(i)) % u64::from(self.group) == 0 {
} else if (self.window_pos.0 + i) % group == 0 {
visitor.group();
}
}
Expand All @@ -138,18 +142,20 @@ impl HexReader {
}

pub fn visit_visual(&self, visitor: &mut VisualVisitor) {
let cap = self.capture.as_slice();
let capture = self.capture.as_slice();
let line_cap = u64::from(self.window_size.0);
let group = u64::from(self.group);

let mut i = 0;
for b in cap {
for b in capture {
i += 1;
let r = *b as usize;
let r = usize::from(*b);
visitor.visual_element(r);

if i == self.window_size.0 {
if i == line_cap {
visitor.next_line();
i = 0;
} else if (self.window_pos.0 + u64::from(i)) % u64::from(self.group) == 0 {
} else if (self.window_pos.0 + i) % group == 0 {
visitor.group();
}
}
Expand Down Expand Up @@ -195,10 +201,12 @@ impl HexReader {

#[cfg(test)]
mod tests {
use super::*;
use std::io::Write;

use tempfile;

use super::*;

impl OffsetsVisitor for String {
fn offset(&mut self, offset: &str) {
self.push_str(offset);
Expand Down
4 changes: 3 additions & 1 deletion src/set_width_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::convert::TryFrom;

use cursive::Cursive;
use cursive::event::Key;
use cursive::traits::{Boxable, Identifiable};
Expand Down Expand Up @@ -68,7 +70,7 @@ fn do_set_widths(s: &mut Cursive) {
match parse_number(&group) {
Ok(group) => s.call_on_id("hex_view", |v: &mut HexView| {
if group > 0 && group < u64::from(std::u16::MAX) {
v.set_group(group as u16);
v.set_group(u16::try_from(group).unwrap());
}
}),
_ => None,
Expand Down

0 comments on commit e798b1a

Please sign in to comment.