From 1907bbb20018922ffd469bfbc784d21919496a63 Mon Sep 17 00:00:00 2001 From: "J. Hinchliffe" Date: Sun, 22 Jun 2025 00:30:27 +0100 Subject: [PATCH] misc: clippy fixes --- Cargo.lock | 1 + assembler/src/assembler/parser.rs | 16 ++++++++-------- assembler/src/main.rs | 8 ++++---- assembler/src/tooling/project.rs | 2 +- assembler/src/util/mod.rs | 2 +- emulator/Cargo.toml | 2 ++ emulator/src/emulator/misc/rpc.rs | 9 +-------- emulator/src/emulator/system/emulator.rs | 2 +- emulator/src/emulator/ui/editor.rs | 5 ++--- 9 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8df113..60f846a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1064,6 +1064,7 @@ dependencies = [ "rfd", "serde", "toml", + "winit", ] [[package]] diff --git a/assembler/src/assembler/parser.rs b/assembler/src/assembler/parser.rs index 73c23fa..9f8734d 100644 --- a/assembler/src/assembler/parser.rs +++ b/assembler/src/assembler/parser.rs @@ -108,10 +108,10 @@ impl Parser { let dest = expect_type!(self.next()?, Register)?; let mut offset = Token::Immediate(0); - if let Ok(next) = self.peek_next() { - if expect_type!(next, Immediate).is_ok() { - offset = self.next()?; - } + if let Ok(next) = self.peek_next() + && expect_type!(next, Immediate).is_ok() + { + offset = self.next()?; } args = vec![base, dest, offset]; @@ -120,10 +120,10 @@ impl Parser { let base = expect_type!(self.next()?, Register)?; let dest = expect_type!(self.next()?, Register, Symbol)?; let mut offset = Token::Immediate(0); - if let Ok(next) = self.peek_next() { - if expect_type!(next, Immediate).is_ok() { - offset = self.next()?; - } + if let Ok(next) = self.peek_next() + && expect_type!(next, Immediate).is_ok() + { + offset = self.next()?; } args = vec![base, dest, offset]; } diff --git a/assembler/src/main.rs b/assembler/src/main.rs index 0d4f523..d1f61cc 100644 --- a/assembler/src/main.rs +++ b/assembler/src/main.rs @@ -23,7 +23,7 @@ fn main() { let mut output_file = match fs::File::create(output_path) { Ok(file) => file, Err(e) => { - eprintln!("Failed to create output file: {}", e); + eprintln!("Failed to create output file: {e}"); std::process::exit(1); } }; @@ -33,7 +33,7 @@ fn main() { // Assemble the source file if let Err(e) = engine.assemble(&src) { - eprintln!("Assembly error: {}", e); + eprintln!("Assembly error: {e}"); std::process::exit(1); } @@ -43,13 +43,13 @@ fn main() { for instruction in instructions { if let Err(e) = output_file.write_all(&instruction.encode().to_le_bytes()) { - eprintln!("Failed to write to output file: {}", e); + eprintln!("Failed to write to output file: {e}"); std::process::exit(1); } } } Some(Err(e)) => { - eprintln!("Build error: {}", e); + eprintln!("Build error: {e}"); std::process::exit(1); } None => { diff --git a/assembler/src/tooling/project.rs b/assembler/src/tooling/project.rs index 9195872..bdab388 100644 --- a/assembler/src/tooling/project.rs +++ b/assembler/src/tooling/project.rs @@ -20,7 +20,7 @@ pub fn tool_libcreate() { _ => panic!("Invalid project type"), }; - let path = format!("{}/{}.dsa", project_path, project_name); + let path = format!("{project_path}/{project_name}.dsa"); std::fs::write(path, template).expect("Unable to write file"); } diff --git a/assembler/src/util/mod.rs b/assembler/src/util/mod.rs index ea56139..01f628d 100644 --- a/assembler/src/util/mod.rs +++ b/assembler/src/util/mod.rs @@ -3,7 +3,7 @@ pub mod logging; use std::io::Write; pub fn input(prompt: &str) -> String { - print!("{}\n > ", prompt); + print!("{prompt}\n > "); std::io::stdout().flush().unwrap(); let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); diff --git a/emulator/Cargo.toml b/emulator/Cargo.toml index b72f082..722882e 100644 --- a/emulator/Cargo.toml +++ b/emulator/Cargo.toml @@ -7,6 +7,7 @@ default-run = "emulator" [lib] name = "dsa_rs" path = "src/lib.rs" +type = "cdylib" [[bin]] name = "emulator" @@ -23,6 +24,7 @@ dirs = "6.0.0" discord-presence = { version = "1.6.0", optional = true } toml = { version = "0.8.23", optional = true } serde = { version = "1.0.219", features = ["derive"], optional = true } +winit = { version = "0.30.11", features = ["android-native-activity"] } [features] default = ["config"] diff --git a/emulator/src/emulator/misc/rpc.rs b/emulator/src/emulator/misc/rpc.rs index 183d773..086750d 100644 --- a/emulator/src/emulator/misc/rpc.rs +++ b/emulator/src/emulator/misc/rpc.rs @@ -16,14 +16,7 @@ //! //! Alternatively, you can hide this in your Discord settings. -use std::{ - path::PathBuf, - sync::{ - Arc, - mpsc::{Receiver, Sender}, - }, - time::Duration, -}; +use std::sync::mpsc::{Receiver, Sender}; #[cfg(feature = "discord-rpc")] use discord_presence::{Client, DiscordError, models::ActivityTimestamps}; diff --git a/emulator/src/emulator/system/emulator.rs b/emulator/src/emulator/system/emulator.rs index 46638d2..342fcc4 100644 --- a/emulator/src/emulator/system/emulator.rs +++ b/emulator/src/emulator/system/emulator.rs @@ -5,7 +5,7 @@ use std::{ time::Duration, }; -use crate::emulator::misc::rpc::{Activity, RpcClient}; +use crate::emulator::misc::rpc::RpcClient; use crate::emulator::system::{ model::{Command, PersistentState, Running, State}, processor::Processor, diff --git a/emulator/src/emulator/ui/editor.rs b/emulator/src/emulator/ui/editor.rs index 98cc1c2..8c1e1de 100644 --- a/emulator/src/emulator/ui/editor.rs +++ b/emulator/src/emulator/ui/editor.rs @@ -344,8 +344,8 @@ impl Editor { } // builds the current file - if ui.button("Build").clicked() && !self.unsaved { - if let Some(path) = &self.path { + if ui.button("Build").clicked() && !self.unsaved + && let Some(path) = &self.path { let mut assembler = CompilerEngine::new(); if let Err(error) = assembler.assemble(path) { self.error = Some(format!("Failed to assemble: {error:?}")); @@ -371,7 +371,6 @@ impl Editor { .flat_map(|i| i.encode().to_be_bytes().to_vec()) .collect(); } - } // Loads the generated binary into the assembler at the provided offset if ui.button("Load").clicked() {