diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-04 21:09:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-04 21:09:02 +0900 |
| commit | 06e8e14520a4a38fed500581d2b75a42418b22c4 (patch) | |
| tree | 573af18bf6e0933488aea9c1bac47bf4e857546d /crates/shirabe/src/package/handle.rs | |
| parent | a9f19862350c6fd3592d93515d869ffe07ecb399 (diff) | |
| download | php-shirabe-06e8e14520a4a38fed500581d2b75a42418b22c4.tar.gz php-shirabe-06e8e14520a4a38fed500581d2b75a42418b22c4.tar.zst php-shirabe-06e8e14520a4a38fed500581d2b75a42418b22c4.zip | |
feat(package): implement PackageInterface accessor layer for Package/CompletePackage/RootPackage
Fill the trait-impl todo!() across the package accessor layer so loaded
packages are actually usable (the ArrayLoader::load path depends on it):
- Package: implement BasePackage/PackageInterface from struct fields and
existing inherent methods; Display via get_unique_name.
- CompletePackage: delegate PackageInterface to inner Package.
- RootPackage: delegate CompletePackageInterface/PackageInterface to inner
CompletePackage; RootPackageInterface link setters delegate to Package.
Correct three unfaithful trait signatures found during implementation:
- get_target_dir returns Option<String> (PHP computes a normalized value;
a borrow cannot represent it, and AliasPackage could not implement &str
across its aliasOf handle).
- RootPackageInterface link setters take IndexMap<String, Link>, matching
Package and the real ArrayLoader caller (PHP RootPackage inherits
Package::setRequires; the Link[] docblock was imprecise).
- get_full_pretty_version takes a DisplayMode enum instead of a raw i64;
the match is now exhaustive, so it returns String without an error path.
Move mirror conversion to the boundaries: PackageInterface mirror methods
use Vec<Mirror> (the typed form, matching the inherent methods), with
array<->Mirror conversion done by the producer (ComposerRepository) and
consumer (ArrayDumper).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/handle.rs')
| -rw-r--r-- | crates/shirabe/src/package/handle.rs | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/crates/shirabe/src/package/handle.rs b/crates/shirabe/src/package/handle.rs index aecc219..aa21bf1 100644 --- a/crates/shirabe/src/package/handle.rs +++ b/crates/shirabe/src/package/handle.rs @@ -193,7 +193,7 @@ macro_rules! delegate_package_interface_to_inner { fn get_type(&self) -> &str { self.$field.get_type() } - fn get_target_dir(&self) -> Option<&str> { + fn get_target_dir(&self) -> Option<String> { self.$field.get_target_dir() } fn get_extra(&self) -> indexmap::IndexMap<String, shirabe_php_shim::PhpMixed> { @@ -217,15 +217,10 @@ macro_rules! delegate_package_interface_to_inner { fn get_source_reference(&self) -> Option<&str> { self.$field.get_source_reference() } - fn get_source_mirrors( - &self, - ) -> Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>> { + fn get_source_mirrors(&self) -> Option<Vec<crate::package::Mirror>> { self.$field.get_source_mirrors() } - fn set_source_mirrors( - &mut self, - mirrors: Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>>, - ) { + fn set_source_mirrors(&mut self, mirrors: Option<Vec<crate::package::Mirror>>) { self.$field.set_source_mirrors(mirrors); } fn get_dist_type(&self) -> Option<&str> { @@ -243,15 +238,10 @@ macro_rules! delegate_package_interface_to_inner { fn get_dist_sha1_checksum(&self) -> Option<&str> { self.$field.get_dist_sha1_checksum() } - fn get_dist_mirrors( - &self, - ) -> Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>> { + fn get_dist_mirrors(&self) -> Option<Vec<crate::package::Mirror>> { self.$field.get_dist_mirrors() } - fn set_dist_mirrors( - &mut self, - mirrors: Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>>, - ) { + fn set_dist_mirrors(&mut self, mirrors: Option<Vec<crate::package::Mirror>>) { self.$field.set_dist_mirrors(mirrors); } fn get_version(&self) -> &str { @@ -260,7 +250,11 @@ macro_rules! delegate_package_interface_to_inner { fn get_pretty_version(&self) -> &str { self.$field.get_pretty_version() } - fn get_full_pretty_version(&self, truncate: bool, display_mode: i64) -> String { + fn get_full_pretty_version( + &self, + truncate: bool, + display_mode: crate::package::DisplayMode, + ) -> String { self.$field.get_full_pretty_version(truncate, display_mode) } fn get_release_date(&self) -> Option<chrono::DateTime<chrono::Utc>> { @@ -408,11 +402,7 @@ macro_rules! impl_package_interface_handle { } pub fn get_target_dir(&self) -> Option<String> { - self.0 - .borrow() - .as_package_interface() - .get_target_dir() - .map(str::to_string) + self.0.borrow().as_package_interface().get_target_dir() } pub fn get_extra(&self) -> indexmap::IndexMap<String, shirabe_php_shim::PhpMixed> { @@ -462,16 +452,11 @@ macro_rules! impl_package_interface_handle { .map(str::to_string) } - pub fn get_source_mirrors( - &self, - ) -> Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>> { + pub fn get_source_mirrors(&self) -> Option<Vec<crate::package::Mirror>> { self.0.borrow().as_package_interface().get_source_mirrors() } - pub fn set_source_mirrors( - &self, - mirrors: Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>>, - ) { + pub fn set_source_mirrors(&self, mirrors: Option<Vec<crate::package::Mirror>>) { self.0 .borrow_mut() .as_package_interface_mut() @@ -514,16 +499,11 @@ macro_rules! impl_package_interface_handle { .map(str::to_string) } - pub fn get_dist_mirrors( - &self, - ) -> Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>> { + pub fn get_dist_mirrors(&self) -> Option<Vec<crate::package::Mirror>> { self.0.borrow().as_package_interface().get_dist_mirrors() } - pub fn set_dist_mirrors( - &self, - mirrors: Option<Vec<indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>>>, - ) { + pub fn set_dist_mirrors(&self, mirrors: Option<Vec<crate::package::Mirror>>) { self.0 .borrow_mut() .as_package_interface_mut() @@ -546,7 +526,11 @@ macro_rules! impl_package_interface_handle { .to_string() } - pub fn get_full_pretty_version(&self, truncate: bool, display_mode: i64) -> String { + pub fn get_full_pretty_version( + &self, + truncate: bool, + display_mode: crate::package::DisplayMode, + ) -> String { self.0 .borrow() .as_package_interface() @@ -997,7 +981,7 @@ macro_rules! impl_root_package_interface_handle { .clone() } - pub fn set_requires(&self, requires: Vec<crate::package::Link>) { + pub fn set_requires(&self, requires: indexmap::IndexMap<String, crate::package::Link>) { self.0 .borrow_mut() .as_root_package_interface_mut() @@ -1005,7 +989,10 @@ macro_rules! impl_root_package_interface_handle { .set_requires(requires); } - pub fn set_dev_requires(&self, dev_requires: Vec<crate::package::Link>) { + pub fn set_dev_requires( + &self, + dev_requires: indexmap::IndexMap<String, crate::package::Link>, + ) { self.0 .borrow_mut() .as_root_package_interface_mut() @@ -1013,7 +1000,10 @@ macro_rules! impl_root_package_interface_handle { .set_dev_requires(dev_requires); } - pub fn set_conflicts(&self, conflicts: Vec<crate::package::Link>) { + pub fn set_conflicts( + &self, + conflicts: indexmap::IndexMap<String, crate::package::Link>, + ) { self.0 .borrow_mut() .as_root_package_interface_mut() @@ -1021,7 +1011,7 @@ macro_rules! impl_root_package_interface_handle { .set_conflicts(conflicts); } - pub fn set_provides(&self, provides: Vec<crate::package::Link>) { + pub fn set_provides(&self, provides: indexmap::IndexMap<String, crate::package::Link>) { self.0 .borrow_mut() .as_root_package_interface_mut() @@ -1029,7 +1019,7 @@ macro_rules! impl_root_package_interface_handle { .set_provides(provides); } - pub fn set_replaces(&self, replaces: Vec<crate::package::Link>) { + pub fn set_replaces(&self, replaces: indexmap::IndexMap<String, crate::package::Link>) { self.0 .borrow_mut() .as_root_package_interface_mut() |
