pub fn load_from_disk(path: &Path) -> Result<OfficialIndex>Expand description
What: Load an official package index from a JSON file on disk.
Inputs:
path: File path to read the JSON index from.
Output:
- Returns
Ok(OfficialIndex)with the deserialized index on success. - Returns
Err(ArchToolkitError::Io)if the file cannot be read. - Returns
Err(ArchToolkitError::Json)if the content is not valid index JSON.
Details:
- Rebuilds the
name_to_idxHashMapafter deserialization so O(1) name lookups viafind_package_by_name()work immediately. - Unlike Pacsea’s original implementation, errors are propagated instead of silently ignored; callers decide how to handle a missing or corrupt index.
§Errors
Returns an error if the file cannot be read or the JSON cannot be parsed.
§Example
use arch_toolkit::index::load_from_disk;
use std::path::Path;
let index = load_from_disk(Path::new("official_index.json"))?;
println!("Loaded {} packages", index.pkgs.len());