pub struct ComponentManager { /* private fields */ }Implementations§
Source§impl ComponentManager
impl ComponentManager
pub fn from_lock( lock: ComponentLock, cache_root: impl Into<PathBuf>, target: impl Into<String>, host: AlefHostApiV1, ) -> Result<Self, ComponentError>
Sourcepub fn with_host_services(self, services: Arc<dyn HostServices>) -> Self
pub fn with_host_services(self, services: Arc<dyn HostServices>) -> Self
Expose services to components loaded from now on, through the host table’s
service_call / service_notify callbacks. Components already loaded keep the table
they were created with, so call this before Self::ensure_contract.
Sourcepub fn offline(self, offline: bool) -> Self
pub fn offline(self, offline: bool) -> Self
Disable network downloads: Self::ensure_contract and Self::prefetch fail a
missing artifact with ComponentError::Offline instead of attempting a request. An
artifact already cached on disk is unaffected. Generated bindings call this when the
crate-specific {CRATE}_COMPONENT_OFFLINE environment variable is set.
Sourcepub fn with_download_options(self, options: DownloadOptions) -> Self
pub fn with_download_options(self, options: DownloadOptions) -> Self
Tune downloads: timeouts, retry policy, progress reporting and cancellation. Applies to
Self::ensure_contract and Self::prefetch.
Sourcepub fn with_url_override(
self,
resolve: impl Fn(&ComponentLockEntry) -> String + Send + Sync + 'static,
) -> Self
pub fn with_url_override( self, resolve: impl Fn(&ComponentLockEntry) -> String + Send + Sync + 'static, ) -> Self
Download from resolve(entry) instead of the lock entry’s url, for mirrors and
air-gapped hosts. The archive size, SHA-256 and signature are still checked against the
lock, so a mirror cannot substitute different content. A file:// URL reads from disk.
let manager = manager.with_url_override(|entry| {
entry.url.replacen("https://github.com/", "https://mirror.corp.example/github/", 1)
});Sourcepub fn with_mirror_base(self, base: impl Into<String>) -> Self
pub fn with_mirror_base(self, base: impl Into<String>) -> Self
Download every archive from base instead of the lock’s URL, keeping only the archive
file name: {base}/{file name}. A trailing slash on base is ignored.
Sourcepub fn with_verified_stamp(self, enabled: bool) -> Self
pub fn with_verified_stamp(self, enabled: bool) -> Self
Skip re-hashing installed libraries that match their verified stamp. See
ArtifactCache::with_verified_stamp for the threat model.
Sourcepub fn lock_entry(
&self,
component_id: &str,
) -> Result<&ComponentLockEntry, ComponentError>
pub fn lock_entry( &self, component_id: &str, ) -> Result<&ComponentLockEntry, ComponentError>
The lock entry for component_id on this manager’s target, whatever its delivery mode.
Sourcepub fn lock_entries(&self) -> Vec<&ComponentLockEntry>
pub fn lock_entries(&self) -> Vec<&ComponentLockEntry>
Every lock entry for this manager’s target, sorted by component id.
Sourcepub fn list_cached(&self) -> Result<Vec<CachedObject>, ComponentError>
pub fn list_cached(&self) -> Result<Vec<CachedObject>, ComponentError>
Every object installed in the cache, including ones other host versions installed.
component names the lock entry referencing the object, when this lock has one.
Sourcepub fn remove(
&self,
component_id: &str,
) -> Result<RemovalReport, ComponentError>
pub fn remove( &self, component_id: &str, ) -> Result<RemovalReport, ComponentError>
Remove component_id’s cached object. It re-downloads on next use. On Windows an
object whose library is loaded cannot be deleted; it is reported under skipped.
Sourcepub fn prune(&self, retain: &Retain) -> Result<RemovalReport, ComponentError>
pub fn prune(&self, retain: &Retain) -> Result<RemovalReport, ComponentError>
Remove cached objects retain does not keep, plus orphaned .install-* staging
directories and stale .lock files. Objects loaded in this process are skipped, as are
files Windows refuses to delete; both are listed in the report.
Sourcepub fn ensure_contract(
&self,
component_id: &str,
contract_name: &str,
entry_symbol: &[u8],
) -> Result<Arc<LoadedComponent>, ComponentError>
pub fn ensure_contract( &self, component_id: &str, contract_name: &str, entry_symbol: &[u8], ) -> Result<Arc<LoadedComponent>, ComponentError>
Load one contract a component provides.
entry_symbol is that contract’s NUL-terminated producer entry-point
symbol (alef::codegen::component::entry_point_symbol); the caller
supplies it because computing it requires the same identifier-casing
logic the producer used, which this crate does not depend on.
Concurrent calls for the same (component_id, contract_name) coalesce onto one
download-and-load: a second caller waits behind the first instead of racing a
duplicate download or dlopen. A call for a different key is unaffected and proceeds
immediately – the mutex guarding the loaded-component map is only ever held for a
map lookup or insert, never across I/O.
pub fn prefetch( &self, component_ids: &[&str], ) -> Result<Vec<CachedArtifact>, ComponentError>
Sourcepub fn status(
&self,
component_id: &str,
) -> Result<ComponentStatus, ComponentError>
pub fn status( &self, component_id: &str, ) -> Result<ComponentStatus, ComponentError>
Report where component_id currently stands. Unlike Self::ensure_contract,
Self::prefetch, and Self::cache_path, a Bundled entry is a legitimate answer
here rather than a failure: it is this manager’s way of saying “linked in ahead of
time, never downloaded or loaded through me”, not an error.