Skip to main content

is_explicit

Function is_explicit 

Source
pub fn is_explicit(
    name: &str,
    mode: InstalledPackagesMode,
    cache: Option<&HashSet<String>>,
) -> bool
Expand description

What: Check if a package is explicitly installed, using cache if provided or querying pacman directly.

Inputs:

  • name: Package name to check.
  • mode: Filter mode for query type (LeafOnly or AllExplicit).
  • cache: Optional reference to a HashSet<String> containing explicit package names.

Output:

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

Details:

  • If cache is provided, checks membership in the cache (O(1) lookup).
  • If cache is None, queries pacman directly using the appropriate command for the mode.
  • Gracefully degrades: returns false on error.

ยงExample

use arch_toolkit::index::{is_explicit, InstalledPackagesMode};
use std::collections::HashSet;

let cache = HashSet::from(["vim".to_string(), "git".to_string()]);
assert!(is_explicit("vim", InstalledPackagesMode::AllExplicit, Some(&cache)));
assert!(!is_explicit("nonexistent", InstalledPackagesMode::AllExplicit, Some(&cache)));