Skip to main content

is_installed

Function is_installed 

Source
pub fn is_installed(name: &str, cache: Option<&HashSet<String>>) -> bool
Expand 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 a HashSet<String> containing installed package names.

Output:

  • Returns true if the package is installed, false otherwise.

Details:

  • If cache is provided, checks membership in the cache (O(1) lookup).
  • If cache is None, queries pacman directly using pacman -Q.
  • Gracefully degrades: returns false on 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)));