aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/composite_repository.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-28 22:43:11 +0900
committernsfisis <nsfisis@gmail.com>2026-05-28 22:43:43 +0900
commiteea4efe87e455742ec17881ee93d8095925e8516 (patch)
tree6d242f4fdd0bf32f0494a6fbbd62bce9ed6e1dc7 /crates/shirabe/src/repository/composite_repository.rs
parentcc5d73c05a0abca2eebcc8a6afa0b1543ee49850 (diff)
downloadphp-shirabe-eea4efe87e455742ec17881ee93d8095925e8516.tar.gz
php-shirabe-eea4efe87e455742ec17881ee93d8095925e8516.tar.zst
php-shirabe-eea4efe87e455742ec17881ee93d8095925e8516.zip
refactor(repository): introduce Rc<RefCell<_>> handles for repositories
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository/composite_repository.rs')
-rw-r--r--crates/shirabe/src/repository/composite_repository.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/crates/shirabe/src/repository/composite_repository.rs b/crates/shirabe/src/repository/composite_repository.rs
index 12f1837..6c167f2 100644
--- a/crates/shirabe/src/repository/composite_repository.rs
+++ b/crates/shirabe/src/repository/composite_repository.rs
@@ -8,16 +8,17 @@ use shirabe_semver::constraint::AnyConstraint;
use crate::package::BasePackageHandle;
use crate::package::PackageInterfaceHandle;
use crate::repository::{
- FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface, SearchResult,
+ FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface,
+ RepositoryInterfaceHandle, SearchResult,
};
#[derive(Debug)]
pub struct CompositeRepository {
- repositories: Vec<Box<dyn RepositoryInterface>>,
+ repositories: Vec<RepositoryInterfaceHandle>,
}
impl CompositeRepository {
- pub fn new(repositories: Vec<Box<dyn RepositoryInterface>>) -> Self {
+ pub fn new(repositories: Vec<RepositoryInterfaceHandle>) -> Self {
let mut this = Self {
repositories: vec![],
};
@@ -27,7 +28,7 @@ impl CompositeRepository {
this
}
- pub fn get_repositories(&self) -> &Vec<Box<dyn RepositoryInterface>> {
+ pub fn get_repositories(&self) -> &Vec<RepositoryInterfaceHandle> {
&self.repositories
}
@@ -39,10 +40,17 @@ impl CompositeRepository {
}
}
- pub fn add_repository(&mut self, repository: Box<dyn RepositoryInterface>) {
- if let Some(composite) = repository.as_any().downcast_ref::<CompositeRepository>() {
- for repo in composite.get_repositories() {
- self.repositories.push(repo.clone_box());
+ pub fn add_repository(&mut self, repository: RepositoryInterfaceHandle) {
+ let nested: Option<Vec<RepositoryInterfaceHandle>> = {
+ let repo_ref = repository.borrow();
+ repo_ref
+ .as_any()
+ .downcast_ref::<CompositeRepository>()
+ .map(|composite| composite.get_repositories().clone())
+ };
+ if let Some(nested) = nested {
+ for repo in nested {
+ self.repositories.push(repo);
}
} else {
self.repositories.push(repository);
@@ -163,6 +171,6 @@ impl RepositoryInterface for CompositeRepository {
}
fn as_any(&self) -> &dyn std::any::Any {
- todo!()
+ self
}
}