cargo clippy

This commit is contained in:
Sam Hadow 2025-04-11 10:52:18 +02:00
parent 9058b1e1c2
commit 477587aa68
2 changed files with 25 additions and 16 deletions

View File

@ -1,7 +1,7 @@
use std::fs;
use std::path::Path;
use rug::Integer; use rug::Integer;
use std::fs;
use std::io; use std::io;
use std::path::Path;
pub struct AgcdInput { pub struct AgcdInput {
pub noise_bits: usize, pub noise_bits: usize,
@ -21,16 +21,19 @@ pub fn parse_file(path: &Path) -> io::Result<AgcdInput> {
if trimmed.starts_with("//") { if trimmed.starts_with("//") {
continue; // Skip comment lines continue; // Skip comment lines
} }
break trimmed.parse::<usize>() break trimmed.parse::<usize>().map_err(|e| {
.map_err(|e| io::Error::new( io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
format!("First non-comment line must be noise_bits (usize): {}", e) format!("First non-comment line must be noise_bits (usize): {}", e),
))?; )
}, })?;
None => return Err(io::Error::new( }
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
"Input file is empty or contains only comments" "Input file is empty or contains only comments",
)), ))
}
} }
}; };
@ -44,9 +47,12 @@ pub fn parse_file(path: &Path) -> io::Result<AgcdInput> {
if numbers.len() < 2 { if numbers.len() < 2 {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::InvalidData, 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,
})
} }

View File

@ -1,8 +1,8 @@
mod agcd; mod agcd;
mod file;
mod lll; mod lll;
mod matrix; mod matrix;
mod utils; mod utils;
mod file;
use crate::agcd::agcd; use crate::agcd::agcd;
use crate::file::parse_file; use crate::file::parse_file;
@ -35,7 +35,10 @@ fn main() -> std::io::Result<()> {
let input = parse_file(path)?; let input = parse_file(path)?;
let result = agcd(input.numbers, input.noise_bits); 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(()) Ok(())