diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-25 00:58:20 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-25 00:58:36 +0900 |
| commit | 1921f173ea219cb4b25847294d2d3fa465550fbb (patch) | |
| tree | 0d30486a2cb9a0c106e5d5827be3f655c60cd871 /crates/shirabe/src/package/alias_package.rs | |
| parent | dbdecaf5a1c54a876b7ee0153d58dd39b1080f97 (diff) | |
| download | php-shirabe-1921f173ea219cb4b25847294d2d3fa465550fbb.tar.gz php-shirabe-1921f173ea219cb4b25847294d2d3fa465550fbb.tar.zst php-shirabe-1921f173ea219cb4b25847294d2d3fa465550fbb.zip | |
refactor(package): introduce Rc<RefCell<_>> handles for packages
PHP packages have reference semantics, so introduce shared-ownership
handles over an AnyPackage enum (PackageInterfaceHandle and friends)
and replace Box<dyn PackageInterface> throughout.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/alias_package.rs')
| -rw-r--r-- | crates/shirabe/src/package/alias_package.rs | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs index e9b5dbf..5558337 100644 --- a/crates/shirabe/src/package/alias_package.rs +++ b/crates/shirabe/src/package/alias_package.rs @@ -8,6 +8,7 @@ use shirabe_semver::constraint::SimpleConstraint; use crate::package::BasePackage; use crate::package::Link; +use crate::package::PackageHandle; use crate::package::PackageInterface; use crate::package::version::VersionParser; use crate::repository::RepositoryInterface; @@ -34,7 +35,7 @@ pub struct AliasPackage { pub(crate) has_self_version_requires: bool, /// @var BasePackage - pub(crate) alias_of: Box<dyn BasePackage>, + pub(crate) alias_of: PackageHandle, /// @var Link[] pub(crate) requires: IndexMap<String, Link>, /// @var Link[] @@ -53,8 +54,8 @@ impl AliasPackage { /// @param BasePackage $aliasOf The package this package is an alias of /// @param string $version The version the alias must report /// @param string $prettyVersion The alias's non-normalized version - pub fn new(alias_of: Box<dyn BasePackage>, version: String, pretty_version: String) -> Self { - let alias_name = alias_of.get_name().to_string(); + pub fn new(alias_of: PackageHandle, version: String, pretty_version: String) -> Self { + let alias_name = alias_of.get_name(); let stability = VersionParser::parse_stability(&version).to_string(); let dev = stability == "dev"; @@ -130,12 +131,8 @@ impl AliasPackage { this } - pub fn get_alias_of(&self) -> &dyn BasePackage { - self.alias_of.as_ref() - } - - pub fn get_alias_of_mut(&mut self) -> &mut dyn BasePackage { - &mut *self.alias_of + pub fn get_alias_of(&self) -> PackageHandle { + self.alias_of.clone() } /// Stores whether this is an alias created by an aliasing in the requirements of the root package or not @@ -244,11 +241,13 @@ impl PackageInterface for AliasPackage { } fn get_name(&self) -> &str { - self.alias_of.get_name() + // PHP delegates to aliasOf; the local name mirrors aliasOf->getName(), + // so it is returned here to avoid borrowing across the shared handle. + &self.name } fn get_pretty_name(&self) -> &str { - self.alias_of.get_pretty_name() + &self.pretty_name } fn get_names(&self, provides: bool) -> Vec<String> { @@ -306,11 +305,14 @@ impl PackageInterface for AliasPackage { } fn get_type(&self) -> &str { - self.alias_of.get_type() + // Delegates to the shared `aliasOf` handle, whose getters yield owned + // `String`s; a borrow cannot escape the `RefCell`. Use the handle API + // (`AliasPackageHandle::get_alias_of().get_type()`) instead. + todo!("AliasPackage::get_type cannot return &str across the aliasOf handle") } fn get_target_dir(&self) -> Option<&str> { - self.alias_of.get_target_dir() + todo!("AliasPackage::get_target_dir cannot return &str across the aliasOf handle") } fn get_extra(&self) -> IndexMap<String, PhpMixed> { @@ -322,15 +324,15 @@ impl PackageInterface for AliasPackage { } fn get_installation_source(&self) -> Option<&str> { - self.alias_of.get_installation_source() + todo!("AliasPackage::get_installation_source cannot return &str across the aliasOf handle") } fn get_source_type(&self) -> Option<&str> { - self.alias_of.get_source_type() + todo!("AliasPackage::get_source_type cannot return &str across the aliasOf handle") } fn get_source_url(&self) -> Option<&str> { - self.alias_of.get_source_url() + todo!("AliasPackage::get_source_url cannot return &str across the aliasOf handle") } fn get_source_urls(&self) -> Vec<String> { @@ -338,7 +340,7 @@ impl PackageInterface for AliasPackage { } fn get_source_reference(&self) -> Option<&str> { - self.alias_of.get_source_reference() + todo!("AliasPackage::get_source_reference cannot return &str across the aliasOf handle") } fn set_source_reference(&mut self, reference: Option<String>) { @@ -354,11 +356,11 @@ impl PackageInterface for AliasPackage { } fn get_dist_type(&self) -> Option<&str> { - self.alias_of.get_dist_type() + todo!("AliasPackage::get_dist_type cannot return &str across the aliasOf handle") } fn get_dist_url(&self) -> Option<&str> { - self.alias_of.get_dist_url() + todo!("AliasPackage::get_dist_url cannot return &str across the aliasOf handle") } fn get_dist_urls(&self) -> Vec<String> { @@ -366,7 +368,7 @@ impl PackageInterface for AliasPackage { } fn get_dist_reference(&self) -> Option<&str> { - self.alias_of.get_dist_reference() + todo!("AliasPackage::get_dist_reference cannot return &str across the aliasOf handle") } fn set_dist_reference(&mut self, reference: Option<String>) { @@ -374,7 +376,7 @@ impl PackageInterface for AliasPackage { } fn get_dist_sha1_checksum(&self) -> Option<&str> { - self.alias_of.get_dist_sha1_checksum() + todo!("AliasPackage::get_dist_sha1_checksum cannot return &str across the aliasOf handle") } fn set_transport_options(&mut self, options: IndexMap<String, PhpMixed>) { @@ -422,7 +424,7 @@ impl PackageInterface for AliasPackage { } fn get_notification_url(&self) -> Option<&str> { - self.alias_of.get_notification_url() + todo!("AliasPackage::get_notification_url cannot return &str across the aliasOf handle") } fn is_default_branch(&self) -> bool { @@ -442,9 +444,8 @@ impl PackageInterface for AliasPackage { } fn get_full_pretty_version(&self, truncate: bool, display_mode: i64) -> String { - // TODO(phase-b): BasePackage.get_full_pretty_version returns Result; bridge here - BasePackage::get_full_pretty_version(self.alias_of.as_ref(), truncate, display_mode) - .unwrap_or_default() + self.alias_of + .get_full_pretty_version(truncate, display_mode) } fn get_unique_name(&self) -> String { @@ -460,7 +461,7 @@ impl PackageInterface for AliasPackage { } fn get_repository(&self) -> Option<&dyn RepositoryInterface> { - self.alias_of.get_repository() + todo!("AliasPackage::get_repository cannot return a borrow across the aliasOf handle") } } @@ -500,8 +501,4 @@ impl BasePackage for AliasPackage { fn take_repository(&mut self) -> Option<Box<dyn RepositoryInterface>> { todo!() } - - fn clone_box(&self) -> Box<dyn BasePackage> { - todo!() - } } |
