diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-28 22:43:11 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-28 22:43:43 +0900 |
| commit | eea4efe87e455742ec17881ee93d8095925e8516 (patch) | |
| tree | 6d242f4fdd0bf32f0494a6fbbd62bce9ed6e1dc7 /crates/shirabe/src/repository/installed_repository.rs | |
| parent | cc5d73c05a0abca2eebcc8a6afa0b1543ee49850 (diff) | |
| download | php-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/installed_repository.rs')
| -rw-r--r-- | crates/shirabe/src/repository/installed_repository.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/shirabe/src/repository/installed_repository.rs b/crates/shirabe/src/repository/installed_repository.rs index 486d4bd..b857bc2 100644 --- a/crates/shirabe/src/repository/installed_repository.rs +++ b/crates/shirabe/src/repository/installed_repository.rs @@ -16,7 +16,8 @@ use crate::repository::LockArrayRepository; use crate::repository::PlatformRepository; use crate::repository::RootPackageRepository; use crate::repository::{ - FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface, SearchResult, + FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface, + RepositoryInterfaceHandle, SearchResult, }; pub enum NeedleInput { @@ -36,7 +37,7 @@ pub struct InstalledRepository { } impl InstalledRepository { - pub fn new(repositories: Vec<Box<dyn RepositoryInterface>>) -> Self { + pub fn new(repositories: Vec<RepositoryInterfaceHandle>) -> Self { let mut this = Self { inner: CompositeRepository::new(vec![]), }; @@ -381,25 +382,21 @@ impl InstalledRepository { results } - pub fn add_repository( - &mut self, - repository: Box<dyn RepositoryInterface>, - ) -> anyhow::Result<()> { - // TODO(phase-b): cannot Any::is::<dyn InstalledRepositoryInterface>; replace with a - // dedicated downcast/marker method on RepositoryInterface. - if repository.as_any().is::<LockArrayRepository>() - || repository.as_any().is::<RootPackageRepository>() - || repository.as_any().is::<PlatformRepository>() + pub fn add_repository(&mut self, repository: RepositoryInterfaceHandle) -> anyhow::Result<()> { + if repository.is::<LockArrayRepository>() + || repository.is::<RootPackageRepository>() + || repository.is::<PlatformRepository>() { self.inner.add_repository(repository); return Ok(()); } + let type_name = std::any::type_name_of_val(&*repository.borrow()).to_string(); + let repo_name = repository.get_repo_name(); Err(anyhow::anyhow!(LogicException { message: format!( "An InstalledRepository can not contain a repository of type {} ({})", - std::any::type_name_of_val(&*repository), - repository.get_repo_name(), + type_name, repo_name, ), code: 0, })) |
