refactor(build): format using cargo fmt

This commit is contained in:
Raphael 2026-02-12 14:05:55 +01:00
parent 07380713b6
commit acf26d6e90
No known key found for this signature in database

View file

@ -1,21 +1,13 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs::{ fs::{self, DirEntry, ReadDir, write},
self,
DirEntry,
ReadDir,
write,
},
io, io,
path::{ path::{Path, PathBuf},
Path,
PathBuf
}
}; };
const COMMAND_DIR: &str = "./src/commands/"; const COMMAND_DIR: &str = "./src/commands/";
const EVENT_DIR: &str = "./src/events"; const EVENT_DIR: &str = "./src/events";
const MOD_PREFIX: &str= "pub mod "; const MOD_PREFIX: &str = "pub mod ";
fn clear_name(s: &mut String, n: usize) -> String { fn clear_name(s: &mut String, n: usize) -> String {
if n >= s.len() { if n >= s.len() {
@ -35,7 +27,10 @@ fn read_dir(dir: &Path) -> Vec<String> {
for entry in fs::read_dir(dir).unwrap() { for entry in fs::read_dir(dir).unwrap() {
let entry: DirEntry = entry.unwrap(); let entry: DirEntry = entry.unwrap();
let pb: PathBuf = entry.path(); let pb: PathBuf = entry.path();
if pb.is_file() && pb.to_string_lossy().ends_with(".rs") && !pb.to_string_lossy().ends_with("mod.rs") { if pb.is_file()
&& pb.to_string_lossy().ends_with(".rs")
&& !pb.to_string_lossy().ends_with("mod.rs")
{
dir_content.push(clear_name(pb.to_string_lossy().to_mut(), len)); dir_content.push(clear_name(pb.to_string_lossy().to_mut(), len));
} }
} }
@ -53,7 +48,7 @@ fn list_srcs(dir: &Path) -> HashMap<String, Vec<String>> {
let pb: PathBuf = entry.path(); let pb: PathBuf = entry.path();
let filename: &str = &pb.to_string_lossy(); let filename: &str = &pb.to_string_lossy();
let len: usize = filename.rfind('/').expect("") + 1; let len: usize = filename.rfind('/').expect("") + 1;
if pb.is_dir() { if pb.is_dir() {
let subdir: Vec<String> = read_dir(pb.as_path()); let subdir: Vec<String> = read_dir(pb.as_path());
to_ret.insert(clear_name(pb.to_string_lossy().to_mut(), len), subdir); to_ret.insert(clear_name(pb.to_string_lossy().to_mut(), len), subdir);
} }
@ -72,10 +67,16 @@ fn commands() -> io::Result<()> {
submodules = String::from(MOD_PREFIX) + command + &String::from(";\n"); submodules = String::from(MOD_PREFIX) + command + &String::from(";\n");
println!("\t'{}'", command); println!("\t'{}'", command);
} }
write(String::from(COMMAND_DIR) + subdir + &String::from("/mod.rs"), submodules)?; write(
String::from(COMMAND_DIR) + subdir + &String::from("/mod.rs"),
submodules,
)?;
modules = modules + &String::from(MOD_PREFIX) + subdir + &String::from(";\n"); modules = modules + &String::from(MOD_PREFIX) + subdir + &String::from(";\n");
} }
write(String::from(COMMAND_DIR) + &String::from("/mod.rs"), modules)?; write(
String::from(COMMAND_DIR) + &String::from("/mod.rs"),
modules,
)?;
Ok(()) Ok(())
} }
@ -91,7 +92,10 @@ fn events() -> io::Result<()> {
submodules = String::from(MOD_PREFIX) + event + &String::from(";\n"); submodules = String::from(MOD_PREFIX) + event + &String::from(";\n");
println!("\t'{}'", event); println!("\t'{}'", event);
} }
write(String::from(EVENT_DIR) + subdir + &String::from("/mod.rs"), submodules)?; write(
String::from(EVENT_DIR) + subdir + &String::from("/mod.rs"),
submodules,
)?;
modules = modules + &String::from(MOD_PREFIX) + subdir + &String::from(";\n"); modules = modules + &String::from(MOD_PREFIX) + subdir + &String::from(";\n");
} }
write(String::from(EVENT_DIR) + &String::from("/mod.rs"), modules)?; write(String::from(EVENT_DIR) + &String::from("/mod.rs"), modules)?;