cargo clippy
This commit is contained in:
parent
9058b1e1c2
commit
477587aa68
34
src/file.rs
34
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<AgcdInput> {
|
||||
if trimmed.starts_with("//") {
|
||||
continue; // Skip comment lines
|
||||
}
|
||||
break trimmed.parse::<usize>()
|
||||
.map_err(|e| io::Error::new(
|
||||
break trimmed.parse::<usize>().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<Integer> = 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::<u64>().ok())
|
||||
.map(Integer::from)
|
||||
.collect();
|
||||
@ -44,9 +47,12 @@ pub fn parse_file(path: &Path) -> io::Result<AgcdInput> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
@ -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(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user