ResourceIterator

Struct ResourceIterator 

Source
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

Source

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 resources
  • manifest - 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
Source

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.

Source

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 search
  • name - The resource name to match
  • source - The source name to match (None for local resources)
§Returns

The resource type and locked resource entry if found

Source

pub fn count_total_resources(lockfile: &LockFile) -> usize

Count total resources in a lockfile

Source

pub fn count_manifest_dependencies(manifest: &Manifest) -> usize

Count total dependencies defined in a manifest

Source

pub fn has_resources(lockfile: &LockFile) -> bool

Check if a lockfile has any resources

Source

pub fn get_all_resource_names(lockfile: &LockFile) -> Vec<String>

Get all resource names from a lockfile

Source

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

Source

pub fn for_each_resource<F>(lockfile: &LockFile, f: F)

Apply a function to all resources of all types

Source

pub fn map_resources<T, F>(lockfile: &LockFile, f: F) -> Vec<T>

Map over all resources and collect results

Source

pub fn filter_resources<F>( lockfile: &LockFile, predicate: F, ) -> Vec<(ResourceType, LockedResource)>

Filter resources based on a predicate

Source

pub fn group_by_source( lockfile: &LockFile, ) -> HashMap<String, Vec<(ResourceType, LockedResource)>>

Group resources by source

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more