pub struct OfficialIndex {
pub pkgs: Vec<OfficialPackage>,
pub name_to_idx: HashMap<String, usize>,
}Expand description
What: Represent the full collection of official packages maintained in memory.
Inputs:
- Populated by fetch and enrichment routines before being persisted or queried.
Output:
- Exposed through API helpers that clone or iterate the package list.
Details:
- Serializable via Serde to allow saving and restoring across sessions.
- The
name_to_idxfield is derived frompkgsand skipped during serialization. - Provides O(1) lookup via
find_package_by_name()whenname_to_idxis populated.
Fields§
§pkgs: Vec<OfficialPackage>All known official packages in the index.
name_to_idx: HashMap<String, usize>Index mapping lowercase package names to their position in pkgs for O(1) lookups.
Skipped during serialization; rebuilt after deserialization via rebuild_name_index().
Implementations§
Source§impl OfficialIndex
impl OfficialIndex
Sourcepub fn rebuild_name_index(&mut self)
pub fn rebuild_name_index(&mut self)
What: Rebuild the name_to_idx HashMap from the current pkgs Vec.
Inputs:
- None (operates on
self.pkgs)
Output:
- Populates
self.name_to_idxwith lowercase package names mapped to indices.
Details:
- Should be called after deserialization or when
pkgsis modified. - Uses lowercase names for case-insensitive lookups.
- Clears existing index before rebuilding to ensure consistency.
Sourcepub fn find_package_by_name(&self, name: &str) -> Option<&OfficialPackage>
pub fn find_package_by_name(&self, name: &str) -> Option<&OfficialPackage>
What: Find a package by name in the official index using O(1) lookup.
Inputs:
name: Package name to search for (case-insensitive)
Output:
Some(&OfficialPackage)if the package is found,Noneotherwise.
Details:
- Uses the
name_to_idxHashMapfor O(1) lookup by lowercase name. - Falls back to linear scan if
HashMapis empty (e.g., before rebuild). - Case-insensitive matching is performed.
Trait Implementations§
Source§impl Clone for OfficialIndex
impl Clone for OfficialIndex
Source§fn clone(&self) -> OfficialIndex
fn clone(&self) -> OfficialIndex
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OfficialIndex
impl Debug for OfficialIndex
Source§impl Default for OfficialIndex
impl Default for OfficialIndex
Source§fn default() -> OfficialIndex
fn default() -> OfficialIndex
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for OfficialIndex
impl<'de> Deserialize<'de> for OfficialIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for OfficialIndex
impl RefUnwindSafe for OfficialIndex
impl Send for OfficialIndex
impl Sync for OfficialIndex
impl Unpin for OfficialIndex
impl UnsafeUnpin for OfficialIndex
impl UnwindSafe for OfficialIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more