aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/repository')
-rw-r--r--crates/shirabe/src/repository/handle.rs63
-rw-r--r--crates/shirabe/src/repository/repository_set.rs6
2 files changed, 64 insertions, 5 deletions
diff --git a/crates/shirabe/src/repository/handle.rs b/crates/shirabe/src/repository/handle.rs
index f7a4104..a4225f7 100644
--- a/crates/shirabe/src/repository/handle.rs
+++ b/crates/shirabe/src/repository/handle.rs
@@ -10,8 +10,8 @@ use shirabe_semver::constraint::AnyConstraint;
use crate::package::BasePackageHandle;
use crate::package::PackageInterfaceHandle;
use crate::repository::{
- FindPackageConstraint, InstalledRepositoryInterface, LoadPackagesResult, ProviderInfo,
- RepositoryInterface, SearchResult, WritableRepositoryInterface,
+ FindPackageConstraint, InstalledRepositoryInterface, LoadPackagesResult, LockArrayRepository,
+ ProviderInfo, RepositoryInterface, SearchResult, WritableRepositoryInterface,
};
/// Shared reference to a repository. Corresponds to PHP `RepositoryInterface`.
@@ -172,3 +172,62 @@ impl std::hash::Hash for RepositoryInterfaceHandle {
self.ptr_id().hash(state);
}
}
+
+/// Typed shared handle over `LockArrayRepository`. Preserves the PHP `?LockArrayRepository`
+/// typing where a `RepositoryInterfaceHandle` would be too wide.
+#[derive(Debug, Clone)]
+pub struct LockArrayRepositoryHandle(Rc<RefCell<LockArrayRepository>>);
+
+impl LockArrayRepositoryHandle {
+ pub fn new(repository: LockArrayRepository) -> Self {
+ let rc: Rc<RefCell<LockArrayRepository>> = Rc::new(RefCell::new(repository));
+ let rc_dyn: Rc<RefCell<dyn RepositoryInterface>> = rc.clone();
+ rc.borrow().set_self_handle(Rc::downgrade(&rc_dyn));
+ Self(rc)
+ }
+
+ pub fn from_rc(rc: Rc<RefCell<LockArrayRepository>>) -> Self {
+ Self(rc)
+ }
+
+ pub fn as_rc(&self) -> &Rc<RefCell<LockArrayRepository>> {
+ &self.0
+ }
+
+ pub fn borrow(&self) -> Ref<'_, LockArrayRepository> {
+ self.0.borrow()
+ }
+
+ pub fn borrow_mut(&self) -> RefMut<'_, LockArrayRepository> {
+ self.0.borrow_mut()
+ }
+
+ pub fn ptr_eq(&self, other: &Self) -> bool {
+ Rc::ptr_eq(&self.0, &other.0)
+ }
+
+ pub fn ptr_id(&self) -> usize {
+ Rc::as_ptr(&self.0) as *const () as usize
+ }
+}
+
+impl From<LockArrayRepositoryHandle> for RepositoryInterfaceHandle {
+ fn from(h: LockArrayRepositoryHandle) -> Self {
+ let rc: Rc<RefCell<dyn RepositoryInterface>> = h.0;
+ RepositoryInterfaceHandle::from_rc(rc)
+ }
+}
+
+impl PartialEq for LockArrayRepositoryHandle {
+ fn eq(&self, other: &Self) -> bool {
+ Rc::ptr_eq(&self.0, &other.0)
+ }
+}
+
+impl Eq for LockArrayRepositoryHandle {}
+
+impl std::hash::Hash for LockArrayRepositoryHandle {
+ fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+ self.ptr_id().hash(state);
+ }
+}
diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs
index f4a4057..843af80 100644
--- a/crates/shirabe/src/repository/repository_set.rs
+++ b/crates/shirabe/src/repository/repository_set.rs
@@ -32,7 +32,7 @@ use crate::package::version::StabilityFilter;
use crate::repository::CompositeRepository;
use crate::repository::InstalledRepository;
use crate::repository::InstalledRepositoryInterface;
-use crate::repository::LockArrayRepository;
+use crate::repository::LockArrayRepositoryHandle;
use crate::repository::PlatformRepository;
use crate::repository::{AdvisoryProviderInterface, PartialOrSecurityAdvisory};
use crate::repository::{FindPackageConstraint, RepositoryInterface, RepositoryInterfaceHandle};
@@ -573,7 +573,7 @@ impl RepositorySet {
pub fn create_pool_for_package(
&mut self,
package_name: &str,
- locked_repo: Option<LockArrayRepository>,
+ locked_repo: Option<LockArrayRepositoryHandle>,
) -> Result<Pool> {
// TODO unify this with above in some simpler version without "request"?
self.create_pool_for_packages(vec![package_name.to_string()], locked_repo)
@@ -583,7 +583,7 @@ impl RepositorySet {
pub fn create_pool_for_packages(
&mut self,
package_names: Vec<String>,
- locked_repo: Option<LockArrayRepository>,
+ locked_repo: Option<LockArrayRepositoryHandle>,
) -> Result<Pool> {
let mut request = Request::new(locked_repo);