pub struct PackageIndex { /* private fields */ }Expand description
An in-memory index of every package (and all of their versions) in a Thunderstore community.
This is the crate’s central read model. Obtain one from
ThunderstoreClient::get_manifest
or refresh_index, then
query it for packages, versions, and download URLs.
Packages are addressed by a numeric index in the range 0..len(). To look up
a package by its Owner-Name identifier, build a map once with
build_name_index, or use
get_package_by_full_name. To pull a
single field without materializing a whole Package, use the resolve_*_at
accessors.
A PackageIndex is built from a Vec<Package> (via From) — for example
the JSON returned by the Thunderstore API — and is what the client persists to
and loads from its on-disk cache.
Implementations§
Source§impl PackageIndex
impl PackageIndex
Sourcepub fn resolve_name_at(&self, idx: usize) -> Option<String>
pub fn resolve_name_at(&self, idx: usize) -> Option<String>
Returns the short package name at idx, or None if idx is out of range
or the name is not set.
Sourcepub fn resolve_full_name_at(&self, idx: usize) -> Option<String>
pub fn resolve_full_name_at(&self, idx: usize) -> Option<String>
Returns the full package name (Owner-Name) at idx, or None if idx is
out of range or the name is not set.
Sourcepub fn search(&self, term: &str) -> Vec<usize>
pub fn search(&self, term: &str) -> Vec<usize>
The indices of every package whose name or Owner-Name full name contains
term, case-insensitively.
Returns indices rather than references so a caller can resolve only the
fields it needs from the interned index. An empty term matches every
package, so clearing a search box shows the full list rather than nothing.
Sourcepub fn resolve_owner_at(&self, idx: usize) -> Option<String>
pub fn resolve_owner_at(&self, idx: usize) -> Option<String>
Returns the owner of the package at idx, or None if idx is out of
range or the owner is not set.
Sourcepub fn name_at(&self, idx: usize) -> Option<&str>
pub fn name_at(&self, idx: usize) -> Option<&str>
Borrows the short package name at idx, or None if idx is out of range
or the name is not set.
Unlike resolve_name_at, this borrows from the
index’s interner and performs no allocation.
Sourcepub fn full_name_at(&self, idx: usize) -> Option<&str>
pub fn full_name_at(&self, idx: usize) -> Option<&str>
Borrows the full package name (Owner-Name) at idx, or None if idx is
out of range or the name is not set.
Unlike resolve_full_name_at, this borrows
from the index’s interner and performs no allocation.
Sourcepub fn owner_at(&self, idx: usize) -> Option<&str>
pub fn owner_at(&self, idx: usize) -> Option<&str>
Borrows the owner of the package at idx, or None if idx is out of
range or the owner is not set.
Unlike resolve_owner_at, this borrows from the
index’s interner and performs no allocation.
Sourcepub fn get_package_by_full_name(&self, full_name: &str) -> Option<Package>
pub fn get_package_by_full_name(&self, full_name: &str) -> Option<Package>
Looks up a package by its full name (Owner-Name) and materializes it,
returning None if no package matches.
Sourcepub fn find_index_by_full_name(&self, full_name: &str) -> Option<usize>
pub fn find_index_by_full_name(&self, full_name: &str) -> Option<usize>
Returns the index of the package with the given full name (Owner-Name),
or None if no package matches.
Sourcepub fn get_package_at(&self, idx: usize) -> Option<Package>
pub fn get_package_at(&self, idx: usize) -> Option<Package>
Materializes a full Package, including all of its versions, from the
package at idx, or None if idx is out of range.
Sourcepub fn build_name_index(&self) -> HashMap<String, usize>
pub fn build_name_index(&self) -> HashMap<String, usize>
Builds a map from each package’s full name (Owner-Name) to its index,
for repeated by-name lookups.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Checks the index for internal consistency.
Returns Ok(()) if the index is well-formed, otherwise an
Error::Cache describing the first problem found. The client runs this
automatically when loading a cached index, so a corrupt or truncated cache
surfaces as a recoverable error rather than a later panic.