pub trait Registry:
Debug
+ Send
+ Sync {
// Required methods
fn version_info<'a>(
&'a self,
id: &'a PackageId,
metadata: Option<&'a Value>,
) -> Pin<Box<dyn Future<Output = Result<Vec<VersionInfo>>> + 'a>>;
fn resolve<'a>(
&'a self,
ref_: &'a PackageRef,
metadata: Option<&'a Value>,
) -> Pin<Box<dyn Future<Output = Result<ResolvedVersion>> + 'a>>;
// Provided method
fn revalidate_checksum<'a>(
&'a self,
ref_: &'a PackageRef,
metadata: Option<&'a Value>,
) -> Result<Option<Checksum>> { ... }
}Expand description
A source that can list available versions and resolve package references.
Every Registry implementation must be Send + Sync so it can be
shared across asynchronous tasks. The trait provides three operations:
version_info— list all known versions of a package.resolve— turn aPackageRefinto aResolvedVersionwith a download URL, checksum, and dependencies.revalidate_checksum— optionally re-compute a checksum from the original source (default: no-op).
§Examples
use loadsmith_registry::{OfflineRegistry, Package, PackageVersion, Registry};
use loadsmith_core::{PackageId, Version, FileUrl, PackageRef};
use std::collections::HashMap;
let package = Package::new(
PackageId::new("author-name"),
vec![PackageVersion::new(
Version::new(1, 0, 0),
FileUrl::try_from_url("https://example.com/pkg.zip").unwrap(),
)],
);
let mut packages = HashMap::new();
packages.insert(PackageId::new("author-name"), package);
let registry = OfflineRegistry::new(packages);
let ref_ = PackageRef::new("author-name", Version::new(1, 0, 0));
let resolved = registry.resolve(&ref_, None).await.unwrap();
assert!(resolved.url.to_string().contains("example.com"));Required Methods§
Sourcefn version_info<'a>(
&'a self,
id: &'a PackageId,
metadata: Option<&'a Value>,
) -> Pin<Box<dyn Future<Output = Result<Vec<VersionInfo>>> + 'a>>
fn version_info<'a>( &'a self, id: &'a PackageId, metadata: Option<&'a Value>, ) -> Pin<Box<dyn Future<Output = Result<Vec<VersionInfo>>> + 'a>>
List all available versions of the package identified by id.
Some registries require additional metadata (e.g. a local filesystem path)
which must be supplied via the metadata parameter as a JSON value.
Sourcefn resolve<'a>(
&'a self,
ref_: &'a PackageRef,
metadata: Option<&'a Value>,
) -> Pin<Box<dyn Future<Output = Result<ResolvedVersion>> + 'a>>
fn resolve<'a>( &'a self, ref_: &'a PackageRef, metadata: Option<&'a Value>, ) -> Pin<Box<dyn Future<Output = Result<ResolvedVersion>> + 'a>>
Resolve a package reference into concrete download information.
Returns a ResolvedVersion containing the download URL, file size,
checksum, and dependency list for the exact version requested by ref_.
Provided Methods§
Sourcefn revalidate_checksum<'a>(
&'a self,
ref_: &'a PackageRef,
metadata: Option<&'a Value>,
) -> Result<Option<Checksum>>
fn revalidate_checksum<'a>( &'a self, ref_: &'a PackageRef, metadata: Option<&'a Value>, ) -> Result<Option<Checksum>>
Re-compute and return the checksum for the package identified by ref_,
or return None if the registry does not support checksum revalidation.
The default implementation returns Ok(None).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".