From 42b5f9e321c918cef542c120ad21ba8a7339eb29 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 25 Jul 2026 12:16:25 +0900 Subject: refactor(operation): replace OperationInterface with AnyOperation enum Operations are only ever constructed by the dependency resolver, so a plugin has no way to inject an implementation of its own and the set is closed. Modelling it as an enum, like AnyPackage, removes the OperationInterface trait together with its two parallel downcast mechanisms (as_any() + downcast_ref, and as_*_operation()) and the get_package() default method that panicked on UpdateOperation. The PHP idiom `$op instanceof UpdateOperation ? getTargetPackage() : getPackage()`, written out at six call sites, becomes AnyOperation::get_target_package(). InstallationManager's three blocks that matched on the type string and then recovered the type with expect() collapse into exhaustive matches. SolverOperation keeps only its TYPE constant; the shared getOperationType()/__toString() implementations move to AnyOperation, which also drops the five Self::TYPE.to_string() allocations. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/tests/dependency_resolver/transaction_test.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/shirabe/tests/dependency_resolver/transaction_test.rs') diff --git a/crates/shirabe/tests/dependency_resolver/transaction_test.rs b/crates/shirabe/tests/dependency_resolver/transaction_test.rs index 99f31c38..3b1006ea 100644 --- a/crates/shirabe/tests/dependency_resolver/transaction_test.rs +++ b/crates/shirabe/tests/dependency_resolver/transaction_test.rs @@ -2,6 +2,7 @@ use crate::test_case::{get_alias_package, get_package, get_version_constraint}; use indexmap::IndexMap; +use shirabe::dependency_resolver::operation::AnyOperation; use shirabe::dependency_resolver::transaction::Transaction; use shirabe::package::Link; use shirabe::package::handle::PackageInterfaceHandle; @@ -62,15 +63,15 @@ impl PartialEq for OperationEntry { fn check_transaction_operations(transaction: &Transaction, expected: Vec) { let mut result: Vec = vec![]; for operation in transaction.get_operations() { - if let Some(update) = operation.as_update_operation() { + if let AnyOperation::Update(update) = operation { result.push(OperationEntry::Update { from: update.get_initial_package(), to: update.get_target_package(), }); } else { result.push(OperationEntry::Job { - job: operation.get_operation_type(), - package: operation.get_package(), + job: operation.get_operation_type().to_string(), + package: operation.get_target_package(), }); } } -- cgit v1.3.1