const NIX_STORE_PREFIX: &str = "/nix/store/"; const NIX_HASH_LENGTH: usize = 32; pub fn extract_package_name(path: &str) -> Option> { let without_prefix = path.strip_prefix(NIX_STORE_PREFIX)?; if without_prefix.len() <= NIX_HASH_LENGTH + 1 { return None; } let after_hash = &without_prefix[NIX_HASH_LENGTH + 1..]; let parts: Vec<&str> = after_hash.split('-').collect(); if parts.is_empty() { return None; } let name_parts: Vec<&str> = parts .iter() .take_while(|part| !part.chars().next().map_or(false, |c| c.is_ascii_digit())) .copied() .collect(); if name_parts.is_empty() { return None; } Some(name_parts) } pub fn extract_package_name_string(path: &str) -> Option { extract_package_name(path).map(|f| f.join("-")) } pub fn extract_full_name(path: &str) -> Option<&str> { let without_prefix = path.strip_prefix(NIX_STORE_PREFIX)?; if without_prefix.len() <= NIX_HASH_LENGTH + 1 { return None; } Some(&without_prefix[NIX_HASH_LENGTH + 1..]) }