pub struct InMemoryIndex { /* private fields */ }Expand description
An in-memory package index backed by a thunderstore client.
Stores package data in a HashMap and supports serialisation to/from
disk for caching.
§Examples
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let client = Client::new();
let index = InMemoryIndex::new(client);Implementations§
Source§impl InMemoryIndex
impl InMemoryIndex
Sourcepub fn new(client: Client) -> Self
pub fn new(client: Client) -> Self
Creates a new empty in-memory index.
§Examples
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::new(Client::new());Sourcepub fn load(client: Client, path: impl AsRef<Path>) -> Result<Self>
pub fn load(client: Client, path: impl AsRef<Path>) -> Result<Self>
Loads a previously saved index from disk, or creates a new one if the file does not exist.
§Examples
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::load(Client::new(), "./index.yaml").unwrap();Sourcepub fn save<F>(&self, path: impl AsRef<Path>, filter: F) -> Result<()>
pub fn save<F>(&self, path: impl AsRef<Path>, filter: F) -> Result<()>
Serialises the index state to a JSON file on disk.
The filter closure controls which packages are included.
§Examples
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::new(Client::new());
index.save("./index.json", |_| true).unwrap();Sourcepub fn lock(&self) -> MutexGuard<'_, RawMutex, State>
pub fn lock(&self) -> MutexGuard<'_, RawMutex, State>
Acquires the inner lock on the index state.
§Examples
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::new(Client::new());
let _state = index.lock();Sourcepub async fn update(&self, community: impl Into<String>) -> Result<()>
pub async fn update(&self, community: impl Into<String>) -> Result<()>
Fetches and stores the package index for a thunderstore community.
§Examples
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::new(Client::new());
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
index.update("lethal-company").await.unwrap();
});Sourcepub async fn version_info(
&self,
id: &PackageId,
) -> Result<Option<Vec<VersionInfo>>>
pub async fn version_info( &self, id: &PackageId, ) -> Result<Option<Vec<VersionInfo>>>
Returns version information for a package, if found.
Returns None when the index is complete and the package is not
present. Returns an IndexNotComplete error when the index has not
been fully populated.
§Examples
use loadsmith_core::PackageId;
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::new(Client::new());
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let versions = index.version_info(&PackageId::new("Author-Pkg")).await.unwrap();
});Sourcepub async fn resolve(
&self,
ref_: &PackageRef,
) -> Result<Option<ResolvedVersion>>
pub async fn resolve( &self, ref_: &PackageRef, ) -> Result<Option<ResolvedVersion>>
Resolves a package reference to a specific version’s download URL, size, and dependencies.
§Examples
use loadsmith_core::{PackageId, PackageRef, Version};
use loadsmith_thunderstore::in_memory::InMemoryIndex;
use thunderstore::Client;
let index = InMemoryIndex::new(Client::new());
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let resolved = index
.resolve(&PackageRef::new(
PackageId::new("Author-Pkg"),
Version::new(1, 0, 0),
))
.await
.unwrap();
});Trait Implementations§
Source§impl Clone for InMemoryIndex
impl Clone for InMemoryIndex
Source§fn clone(&self) -> InMemoryIndex
fn clone(&self) -> InMemoryIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more