From 477587aa68b94dfd516e4d75844748c0f0bf8bbb Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Fri, 11 Apr 2025 10:52:18 +0200 Subject: [PATCH] cargo clippy --- src/file.rs | 34 ++++++++++++++++++++-------------- src/main.rs | 7 +++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/file.rs b/src/file.rs index 6848f8c..71d9f29 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,7 +1,7 @@ -use std::fs; -use std::path::Path; use rug::Integer; +use std::fs; use std::io; +use std::path::Path; pub struct AgcdInput { pub noise_bits: usize, @@ -21,22 +21,25 @@ pub fn parse_file(path: &Path) -> io::Result { if trimmed.starts_with("//") { continue; // Skip comment lines } - break trimmed.parse::() - .map_err(|e| io::Error::new( + break trimmed.parse::().map_err(|e| { + io::Error::new( io::ErrorKind::InvalidData, - format!("First non-comment line must be noise_bits (usize): {}", e) - ))?; - }, - None => return Err(io::Error::new( - io::ErrorKind::InvalidData, - "Input file is empty or contains only comments" - )), + format!("First non-comment line must be noise_bits (usize): {}", e), + ) + })?; + } + None => { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "Input file is empty or contains only comments", + )) + } } }; // Parse numbers from remaining lines let numbers: Vec = lines - .filter(|line| !line.trim().starts_with("//") && !line.trim().is_empty()) // ignore comment and empty lines + .filter(|line| !line.trim().starts_with("//") && !line.trim().is_empty()) // ignore comment and empty lines .filter_map(|line| line.trim().parse::().ok()) .map(Integer::from) .collect(); @@ -44,9 +47,12 @@ pub fn parse_file(path: &Path) -> io::Result { if numbers.len() < 2 { return Err(io::Error::new( io::ErrorKind::InvalidData, - "Need at least 2 numbers to compute AGCD" + "Need at least 2 numbers to compute AGCD", )); } - Ok(AgcdInput { noise_bits, numbers }) + Ok(AgcdInput { + noise_bits, + numbers, + }) } diff --git a/src/main.rs b/src/main.rs index 99a64b4..d4dcd78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ mod agcd; +mod file; mod lll; mod matrix; mod utils; -mod file; use crate::agcd::agcd; use crate::file::parse_file; @@ -35,7 +35,10 @@ fn main() -> std::io::Result<()> { let input = parse_file(path)?; let result = agcd(input.numbers, input.noise_bits); - println!("Approximate GCD with noise_bits={}: {}", input.noise_bits, result); + println!( + "Approximate GCD with noise_bits={}: {}", + input.noise_bits, result + ); } } Ok(())