Apply clippy fixes

This commit is contained in:
Dennis 2024-05-30 16:55:33 +02:00
parent 699ac31383
commit 6960bd42c5
No known key found for this signature in database
GPG Key ID: 6937EAEA33A3FA5D
2 changed files with 28 additions and 21 deletions

View File

@ -1,4 +1,4 @@
use std::{collections::VecDeque, fs, path::PathBuf}; use std::{collections::VecDeque, fs, path::{Path, PathBuf}};
// TODO: port into toolbox-rs // TODO: port into toolbox-rs
pub struct LexicographicFileWalker { pub struct LexicographicFileWalker {
@ -7,11 +7,11 @@ pub struct LexicographicFileWalker {
} }
impl LexicographicFileWalker { impl LexicographicFileWalker {
pub fn new(path: &PathBuf) -> Self { pub fn new(path: &Path) -> Self {
let mut dirs = VecDeque::new(); let mut dirs = VecDeque::new();
if path.is_dir() { if path.is_dir() {
dirs.push_back(path.clone()); dirs.push_back(path.to_path_buf());
} }
Self { Self {

View File

@ -4,6 +4,7 @@ mod common;
use core::panic; use core::panic;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fmt::Display;
use std::fs::{create_dir_all, File}; use std::fs::{create_dir_all, File};
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::PathBuf; use std::path::PathBuf;
@ -229,7 +230,10 @@ fn get_file_as_byte_vec(path: &PathBuf) -> Vec<u8> {
let mut f = File::open(path).expect("no file found"); let mut f = File::open(path).expect("no file found");
let metadata = fs::metadata(path).expect("unable to read metadata"); let metadata = fs::metadata(path).expect("unable to read metadata");
let mut buffer = vec![0; metadata.len() as usize]; let mut buffer = vec![0; metadata.len() as usize];
f.read(&mut buffer).expect("buffer overflow"); match f.read(&mut buffer) {
Ok(l) => assert_eq!(metadata.len() as usize, l, "data was not completely read"),
Err(e) => panic!("Error: {e}"),
}
buffer buffer
} }
@ -241,29 +245,31 @@ enum LoadMethod {
Datastore, Datastore,
Directly, Directly,
} }
impl ToString for LoadMethod { impl Display for LoadMethod {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { let result = match self {
LoadMethod::Mmap => "mmap".into(), LoadMethod::Mmap => "mmap",
LoadMethod::Datastore => "datastore".into(), LoadMethod::Datastore => "datastore",
LoadMethod::Directly => "directly".into(), LoadMethod::Directly => "directly",
} };
write!(f, "{result}")
} }
} }
#[derive(clap::ValueEnum, Clone, Default, Debug)] #[derive(clap::ValueEnum, Clone, Default, Debug)]
enum RoutingAlgorithm { enum RoutingAlgorithm {
#[default] #[default]
CH, Ch,
MLD, Mld,
} }
impl ToString for RoutingAlgorithm { impl Display for RoutingAlgorithm {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { let result = match self {
RoutingAlgorithm::CH => "ch".into(), RoutingAlgorithm::Ch => "ch",
RoutingAlgorithm::MLD => "mld".into(), RoutingAlgorithm::Mld => "mld",
} };
write!(f, "{result}")
} }
} }
// TODO: move to external file // TODO: move to external file
@ -275,7 +281,7 @@ struct Args {
memory: LoadMethod, memory: LoadMethod,
// Number of times to greet // Number of times to greet
#[arg(short, default_value_t = RoutingAlgorithm::CH)] #[arg(short, default_value_t = RoutingAlgorithm::Ch)]
p: RoutingAlgorithm, p: RoutingAlgorithm,
} }
@ -321,7 +327,8 @@ fn main() {
.to_str() .to_str()
.unwrap() .unwrap()
.contains(name) .contains(name)
}).cloned() })
.cloned()
.expect("file exists and is usable") .expect("file exists and is usable")
}); });