summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2019-11-11 01:01:31 +0300
committerOxore <oxore@protonmail.com>2019-11-11 01:01:31 +0300
commitb5be6c86d3764131d328389ceeedeb2af46039cc (patch)
tree1c1ff6ae839a3c06d0e3a1dafcb5ed287abf1a43 /src
parentfdd1c7d66bc5fa0712422af9a069e2a84de8c1a4 (diff)
Fix Clippy's complains
Diffstat (limited to 'src')
-rw-r--r--src/core.rs6
-rw-r--r--src/main.rs9
-rw-r--r--src/ram.rs4
3 files changed, 8 insertions, 11 deletions
diff --git a/src/core.rs b/src/core.rs
index a05d75e..64f65fb 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -55,7 +55,7 @@ impl fmt::Display for Operand {
f,
"{}",
match self {
- Operand::Acc => format!("A"),
+ Operand::Acc => "A".to_string(),
Operand::Direct(dir) => format!("{:x}h", dir),
Operand::Indirect(r) => format!("@{:?}", r),
Operand::Data(data) => format!("#{}", data),
@@ -153,7 +153,7 @@ impl Core {
fn fetch(&mut self) -> Op {
let op = self.op();
self.pc += op.size as u16;
- return op;
+ op
}
///
@@ -180,7 +180,7 @@ impl Core {
}
fn sjmp(&mut self, reladdr: i8) {
- self.pc = (self.pc as i16 + reladdr as i16) as u16;
+ self.pc = (self.pc as i16 + i16::from(reladdr)) as u16;
}
fn map_operand(&self, operand: Isa8051Operand, offset: usize) -> Operand {
diff --git a/src/main.rs b/src/main.rs
index d588823..358ac4e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,6 @@ use std::env;
use std::fs;
use std::io;
use std::io::prelude::*;
-use std::string::String;
use std::sync::{Arc, Condvar, Mutex};
use std::thread::sleep;
use std::{thread, time};
@@ -13,13 +12,13 @@ use self::core::Core;
fn core_worker(mut core: Core, should_stop: &Mutex<bool>, cvar: &Condvar) {
loop {
- while false == *should_stop.lock().unwrap() {
+ while !(*should_stop.lock().unwrap()) {
core.step();
println!("{}", core.op());
sleep(time::Duration::from_millis(1000));
}
- while true == *should_stop.lock().unwrap() {
+ while *should_stop.lock().unwrap() {
let _ = cvar.wait(should_stop.lock().unwrap()).unwrap();
}
}
@@ -51,12 +50,12 @@ fn main() {
println!("Please, specify ihex file");
return;
}
- let data = fs::read_to_string(&args[1]).expect(&format!("Unable to read file {}", &args[1]));
+ let data = fs::read_to_string(&args[1]).unwrap_or_else(|_| panic!("Unable to read file {}", &args[1]));
let asyncpair = Arc::new((Mutex::new(false), Condvar::new()));
let asyncpair2 = asyncpair.clone();
- let core = match Core::new_with_ram_from_hex(String::from(data)) {
+ let core = match Core::new_with_ram_from_hex(data) {
Ok(value) => value,
Err(err_string) => {
println!("{}", err_string);
diff --git a/src/ram.rs b/src/ram.rs
index d0ae084..c9a0641 100644
--- a/src/ram.rs
+++ b/src/ram.rs
@@ -6,9 +6,8 @@ pub struct Ram {
impl fmt::Debug for Ram {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut c = 0;
let mut v: Vec<char> = vec![];
- for x in self.array.into_iter() {
+ for (c, x) in self.array.iter().enumerate() {
for hex_char in format!("{:02X}", *x).chars() {
v.push(hex_char);
}
@@ -16,7 +15,6 @@ impl fmt::Debug for Ram {
if c % 8 == 7 {
v.push('\n');
}
- c += 1;
}
write!(f, "{}", v.iter().collect::<String>())
}