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

main.rs: stop copying Strings needlessly

This commit is contained in:
Bloxx12 2025-05-04 14:41:47 +02:00
parent 4feb513d7e
commit eea426c463
No known key found for this signature in database

View file

@ -1,7 +1,6 @@
use clap::Parser; use clap::Parser;
use core::str; use core::str;
use regex::Regex; use regex::Regex;
use std::{process::Command, string::String};
use std::{collections::HashSet, hash::Hash, process::Command, string::String}; use std::{collections::HashSet, hash::Hash, process::Command, string::String};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -16,9 +15,9 @@ struct Args {
} }
#[derive(Debug, PartialEq, PartialOrd, Eq, Clone, Hash)] #[derive(Debug, PartialEq, PartialOrd, Eq, Clone, Hash)]
struct Package { struct Package<'a> {
name: String, name: &'a str,
version: String, version: &'a str,
} }
// Only there to make the compiler shut up for now. // Only there to make the compiler shut up for now.
@ -109,20 +108,20 @@ fn get_packages(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
Err(BlaErr::LolErr) Err(BlaErr::LolErr)
} }
fn get_version(pack: String) -> Package { fn get_version(pack: &str) -> Package {
// This is bound to break sooner or later // This is bound to break sooner or later
let re = Regex::new(r"^/nix/store/[a-z0-9]+-([^-]+(?:-[^-]+)*)-([\d][^/]*)$").unwrap(); let re = Regex::new(r"^/nix/store/[a-z0-9]+-([^-]+(?:-[^-]+)*)-([\d][^/]*)$").unwrap();
// No cap frfr // No cap frfr
if let Some(cap) = re.captures(&pack) { if let Some(cap) = re.captures(pack) {
let name = cap.get(1).unwrap().as_str().to_string(); let name = cap.get(1).unwrap().as_str();
let version = cap.get(2).unwrap().as_str().to_string(); let version = cap.get(2).unwrap().as_str();
return Package { name, version }; return Package { name, version };
} }
Package { Package {
name: "".to_string(), name: "",
version: "".to_string(), version: "",
} }
} }