pub fn is_installed(name: &str, cache: Option<&HashSet<String>>) -> boolExpand description
What: Check if a package is installed, using cache if provided or querying pacman directly.
Inputs:
name: Package name to check.cache: Optional reference to aHashSet<String>containing installed package names.
Output:
- Returns
trueif the package is installed,falseotherwise.
Details:
- If
cacheis provided, checks membership in the cache (O(1) lookup). - If
cacheisNone, queries pacman directly usingpacman -Q. - Gracefully degrades: returns
falseon error.
ยงExample
use arch_toolkit::index::is_installed;
use std::collections::HashSet;
let cache = HashSet::from(["vim".to_string(), "git".to_string()]);
assert!(is_installed("vim", Some(&cache)));
assert!(!is_installed("nonexistent", Some(&cache)));