1
Fork 0
mirror of https://github.com/RGBCube/dix synced 2025-07-28 12:17:45 +00:00

src/main.rs: cleanup

This commit is contained in:
Bloxx12 2025-05-04 22:24:56 +02:00
parent 9cd4befc31
commit 7ac9c287ec
No known key found for this signature in database

View file

@ -27,10 +27,11 @@ struct Args {
closure_size: bool, closure_size: bool,
} }
// Only there to make the compiler shut up for now. struct Package<'a> {
#[derive(Debug)] name: &'a str,
enum BlaErr { versions: HashSet<&'a str>,
LolErr, /// Save if a package is a dependency of another package
is_dep: bool,
} }
fn main() { fn main() {
@ -57,7 +58,6 @@ fn main() {
let package_list_pre = get_packages(&args.path); let package_list_pre = get_packages(&args.path);
let package_list_post = get_packages(&args.path2); let package_list_post = get_packages(&args.path2);
if let (Ok(package_list_pre), Ok(package_list_post)) = (package_list_pre, package_list_post) {
// Map from packages of the first closure to their version // Map from packages of the first closure to their version
let mut pre = HashMap::<&str, HashSet<&str>>::new(); let mut pre = HashMap::<&str, HashSet<&str>>::new();
@ -153,10 +153,9 @@ fn main() {
println!("Difference: {} MiB", post_size - pre_size); println!("Difference: {} MiB", post_size - pre_size);
} }
} }
}
// gets the packages in a closure // gets the packages in a closure
fn get_packages(path: &std::path::Path) -> Result<Vec<String>, BlaErr> { fn get_packages(path: &std::path::Path) -> Vec<String> {
// get the nix store paths using nix-store --query --references <path> // get the nix store paths using nix-store --query --references <path>
let references = Command::new("nix-store") let references = Command::new("nix-store")
.arg("--query") .arg("--query")
@ -169,14 +168,14 @@ fn get_packages(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
if let Ok(list) = list { if let Ok(list) = list {
let res: Vec<String> = list.lines().map(ToString::to_string).collect(); let res: Vec<String> = list.lines().map(ToString::to_string).collect();
return Ok(res); return res;
} }
} }
Err(BlaErr::LolErr) Vec::new()
} }
// gets the dependencies of the packages in a closure // gets the dependencies of the packages in a closure
fn get_dependencies(path: &std::path::Path) -> Result<Vec<String>, BlaErr> { fn get_dependencies(path: &std::path::Path) -> Vec<String> {
// get the nix store paths using nix-store --query --references <path> // get the nix store paths using nix-store --query --references <path>
let references = Command::new("nix-store") let references = Command::new("nix-store")
.arg("--query") .arg("--query")
@ -189,10 +188,10 @@ fn get_dependencies(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
if let Ok(list) = list { if let Ok(list) = list {
let res: Vec<String> = list.lines().map(ToString::to_string).collect(); let res: Vec<String> = list.lines().map(ToString::to_string).collect();
return Ok(res); return res;
} }
} }
Err(BlaErr::LolErr) Vec::new()
} }
fn get_version<'a>(pack: impl Into<&'a str>) -> (&'a str, &'a str) { fn get_version<'a>(pack: impl Into<&'a str>) -> (&'a str, &'a str) {