From 6acd127fef52ac5ec73caf68e1420a2bc6abf79e Mon Sep 17 00:00:00 2001 From: Ross Andrews Date: Sun, 20 Feb 2022 12:58:52 -0600 Subject: [PATCH] Most linting --- src/address.rs | 4 ++-- src/cpu.rs | 7 ++++--- src/main.rs | 11 ++++------- src/memory.rs | 4 ++-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/address.rs b/src/address.rs index eb04474..caa3461 100644 --- a/src/address.rs +++ b/src/address.rs @@ -8,8 +8,8 @@ impl From for Word { fn from(a: u32) -> Self { Self(a & 0xffffff) } } -impl Into for Word { - fn into(self) -> u32 { self.0 } +impl From for u32 { + fn from(word: Word) -> Self { word.0 } } impl std::ops::Add for Word { diff --git a/src/cpu.rs b/src/cpu.rs index 011bb80..bd30eac 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -5,6 +5,7 @@ use crate::address::Word; use crate::memory::PeekPoke; use std::convert::TryFrom; +#[allow(clippy::upper_case_acronyms)] struct CPU { memory: Memory, // Main memory, all of it pc: Word, // program counter, address of the low byte of the instruction @@ -80,7 +81,7 @@ impl CPU { let arg_length = instruction & 3; if arg_length == 0 { Ok(Instruction { - opcode: opcode, + opcode, arg: None, length: 1 }) @@ -88,11 +89,11 @@ impl CPU { let mut arg = 0u32; for n in 0..arg_length { let mut b: u32 = self.memory.peek(self.pc + (n + 1) as i32) as u32; - b = b << (8 * n); + b <<= 8 * n; arg += b; } Ok(Instruction { - opcode: opcode, + opcode, arg: Some(arg), length: arg_length + 1 }) diff --git a/src/main.rs b/src/main.rs index 1638d69..4aa05a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,12 +11,9 @@ use winit::{ dpi::LogicalSize }; -use pixels::{Error, Pixels, SurfaceTexture}; +use pixels::{Pixels, SurfaceTexture}; use rand::RngCore; -use rand::prelude::ThreadRng; -use std::time::{Instant, Duration}; -use pixels::wgpu::Instance; -use std::convert::TryInto; +use std::time::Instant; fn main() { let event_loop = EventLoop::new(); @@ -50,7 +47,7 @@ fn main() { let start = Instant::now(); draw(pixels.get_frame()); let draw_time = Instant::now() - start; - pixels.render(); + pixels.render().expect("Problem displaying framebuffer"); let total_time = Instant::now() - start; println!("Tick took {} total, {} to draw", total_time.as_micros(), draw_time.as_micros()); } @@ -63,7 +60,7 @@ fn draw(frame: &mut [u8]) { assert_eq!(frame.len(), 640 * 480 * 4); let mut rng = rand::thread_rng(); - for (i, pixel) in frame.chunks_exact_mut(4).enumerate() { + for (_, pixel) in frame.chunks_exact_mut(4).enumerate() { let p = rng.next_u32(); let [low, mid, high, _] = p.to_le_bytes(); pixel[0] = low; diff --git a/src/memory.rs b/src/memory.rs index 2f680e4..7961292 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -61,8 +61,8 @@ pub trait PeekPoke { } impl PeekPoke for Memory { - fn peek(&self, addr: Word) -> u8 { self[addr.into()] } - fn poke(&mut self, addr: Word, val: u8) { self[addr.into()] = val; } + fn peek(&self, addr: Word) -> u8 { self[addr] } + fn poke(&mut self, addr: Word, val: u8) { self[addr] = val; } } #[cfg(test)]