pub struct ResourceIterator;Expand description
Iterator utilities for working with resources across all types
The ResourceIterator provides static methods for collecting and processing
resources from lockfiles in a unified way. It’s designed to support the parallel
installation architecture by providing efficient collection methods that work
with the worktree-based installer.
§Use Cases
- Parallel Installation: Collecting all resources for concurrent processing
- Resource Discovery: Finding specific resources across all types
- Statistics: Gathering counts and information across resource types
- Validation: Iterating over all resources for consistency checks
§Examples
use agpm_cli::core::resource_iterator::ResourceIterator;
use agpm_cli::lockfile::LockFile;
use agpm_cli::manifest::Manifest;
use std::path::Path;
let lockfile = LockFile::load(Path::new("agpm.lock"))?;
let manifest = Manifest::load(Path::new("agpm.toml"))?;
// Collect all resources for parallel installation
let all_entries = ResourceIterator::collect_all_entries(&lockfile, &manifest);
println!("Found {} total resources", all_entries.len());
// Find a specific resource by name
if let Some((resource_type, entry)) =
ResourceIterator::find_resource_by_name(&lockfile, "my-agent") {
println!("Found {} in {}", entry.name, resource_type);
}Implementations§
Source§impl ResourceIterator
impl ResourceIterator
Sourcepub fn collect_all_entries<'a>(
lockfile: &'a LockFile,
manifest: &'a Manifest,
) -> Vec<(&'a LockedResource, Cow<'a, str>)>
pub fn collect_all_entries<'a>( lockfile: &'a LockFile, manifest: &'a Manifest, ) -> Vec<(&'a LockedResource, Cow<'a, str>)>
Collect all lockfile entries with their target directories for parallel processing
This method is optimized for the parallel installation architecture, collecting all resources from the lockfile along with their target installation directories. The returned collection can be directly used by the parallel installer.
§Arguments
lockfile- The lockfile containing all resolved resourcesmanifest- The manifest containing target directory configuration
§Returns
A vector of tuples containing each resource and its target directory.
The order matches the processing order defined by ResourceTypeExt::all().
§Performance
This method is optimized for parallel processing:
- Single allocation for the result vector
- Minimal copying of data (references are returned)
- Predictable iteration order for consistent parallel processing
Sourcepub fn find_resource_by_name<'a>(
lockfile: &'a LockFile,
name: &str,
) -> Option<(ResourceType, &'a LockedResource)>
pub fn find_resource_by_name<'a>( lockfile: &'a LockFile, name: &str, ) -> Option<(ResourceType, &'a LockedResource)>
Find a resource by name across all resource types
§Warning
This method only matches by name and may return the wrong resource
when multiple sources provide resources with the same name.
Consider using Self::find_resource_by_name_and_source instead when
source information is available.
Sourcepub fn find_resource_by_name_and_source<'a>(
lockfile: &'a LockFile,
name: &str,
source: Option<&str>,
) -> Option<(ResourceType, &'a LockedResource)>
pub fn find_resource_by_name_and_source<'a>( lockfile: &'a LockFile, name: &str, source: Option<&str>, ) -> Option<(ResourceType, &'a LockedResource)>
Find a resource by name and source across all resource types
This method matches resources using both name and source, which correctly handles cases where multiple sources provide resources with the same name.
§Arguments
lockfile- The lockfile to searchname- The resource name to matchsource- The source name to match (None for local resources)
§Returns
The resource type and locked resource entry if found
Sourcepub fn count_total_resources(lockfile: &LockFile) -> usize
pub fn count_total_resources(lockfile: &LockFile) -> usize
Count total resources in a lockfile
Sourcepub fn count_manifest_dependencies(manifest: &Manifest) -> usize
pub fn count_manifest_dependencies(manifest: &Manifest) -> usize
Count total dependencies defined in a manifest
Sourcepub fn has_resources(lockfile: &LockFile) -> bool
pub fn has_resources(lockfile: &LockFile) -> bool
Check if a lockfile has any resources
Sourcepub fn get_all_resource_names(lockfile: &LockFile) -> Vec<String>
pub fn get_all_resource_names(lockfile: &LockFile) -> Vec<String>
Get all resource names from a lockfile
Sourcepub fn get_resources_by_source<'a>(
lockfile: &'a LockFile,
resource_type: ResourceType,
source: &str,
) -> Vec<&'a LockedResource>
pub fn get_resources_by_source<'a>( lockfile: &'a LockFile, resource_type: ResourceType, source: &str, ) -> Vec<&'a LockedResource>
Get resources of a specific type by source
Sourcepub fn for_each_resource<F>(lockfile: &LockFile, f: F)
pub fn for_each_resource<F>(lockfile: &LockFile, f: F)
Apply a function to all resources of all types
Sourcepub fn map_resources<T, F>(lockfile: &LockFile, f: F) -> Vec<T>
pub fn map_resources<T, F>(lockfile: &LockFile, f: F) -> Vec<T>
Map over all resources and collect results
Sourcepub fn filter_resources<F>(
lockfile: &LockFile,
predicate: F,
) -> Vec<(ResourceType, LockedResource)>
pub fn filter_resources<F>( lockfile: &LockFile, predicate: F, ) -> Vec<(ResourceType, LockedResource)>
Filter resources based on a predicate
Sourcepub fn group_by_source(
lockfile: &LockFile,
) -> HashMap<String, Vec<(ResourceType, LockedResource)>>
pub fn group_by_source( lockfile: &LockFile, ) -> HashMap<String, Vec<(ResourceType, LockedResource)>>
Group resources by source
Auto Trait Implementations§
impl Freeze for ResourceIterator
impl RefUnwindSafe for ResourceIterator
impl Send for ResourceIterator
impl Sync for ResourceIterator
impl Unpin for ResourceIterator
impl UnwindSafe for ResourceIterator
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more