diff --git a/Cargo.toml b/Cargo.toml index 0f68f8c..0cd37b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,8 +37,9 @@ rstar = "0.12" petgraph = "0.6.5" spade = "2.12.1" serde_json = "1.0" -enum_dispatch = "0.3.13" contracts-try = "0.7" +enum_dispatch = "0.3.13" +derive-getters = "0.5.0" bimap = "0.6.3" log = "0.4" utf8-chars = "3.0.4" diff --git a/src/autorouter/history.rs b/src/autorouter/history.rs index bfc512e..bd3d379 100644 --- a/src/autorouter/history.rs +++ b/src/autorouter/history.rs @@ -2,6 +2,7 @@ //! Handles error scenarios related to command history, maintaining lists of executed //! and undone commands for easy navigation. +use derive_getters::Dissolve; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -15,7 +16,7 @@ pub enum HistoryError { NoNextCommand, } -#[derive(Debug, Default, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Dissolve, Serialize, Deserialize)] pub struct History { done: Vec, undone: Vec, @@ -26,10 +27,6 @@ impl History { Self::default() } - pub fn destruct(self) -> (Vec, Vec) { - (self.done, self.undone) - } - pub fn do_(&mut self, command: Command) { self.done.push(command); } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 0ecf819..b401413 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -3,6 +3,7 @@ use std::cmp::Ordering; use contracts_try::debug_requires; +use derive_getters::Dissolve; use enum_dispatch::enum_dispatch; use thiserror::Error; @@ -69,6 +70,7 @@ impl TryInto<()> for InvokerStatus { } } +#[derive(Dissolve)] pub struct Invoker { pub(super) autorouter: Autorouter, pub(super) history: History, @@ -88,10 +90,6 @@ impl Invoker { } } - pub fn destruct(self) -> (Autorouter, History, Option) { - (self.autorouter, self.history, self.ongoing_command) - } - //#[debug_requires(self.ongoing_command.is_none())] pub fn execute(&mut self, command: Command) -> Result<(), InvokerError> { let mut execute = self.execute_stepper(command)?; @@ -193,7 +191,7 @@ impl Invoker { #[debug_requires(self.ongoing_command.is_none())] pub fn replay(&mut self, history: History) { - let (done, undone) = history.destruct(); + let (done, undone) = history.dissolve(); for command in done { self.execute(command); diff --git a/tests/single_layer.rs b/tests/single_layer.rs index a093f29..cb4ddcf 100644 --- a/tests/single_layer.rs +++ b/tests/single_layer.rs @@ -19,7 +19,7 @@ fn test_0603_breakout() { "tests/single_layer/0603_breakout/autoroute_all.cmd", ); - let (mut autorouter, ..) = invoker.destruct(); + let (mut autorouter, ..) = invoker.dissolve(); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); //common::assert_number_of_conncomps(&mut autorouter, 2); @@ -35,7 +35,7 @@ fn test_tht_diode_bridge_rectifier() { "tests/single_layer/tht_diode_bridge_rectifier/autoroute_all.cmd", ); - let (mut autorouter, ..) = invoker.destruct(); + let (mut autorouter, ..) = invoker.dissolve(); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); //common::assert_number_of_conncomps(&mut autorouter, 4); @@ -69,7 +69,7 @@ fn test_4x_3rd_order_smd_lc_filters() { "tests/single_layer/4x_3rd_order_smd_lc_filters/autoroute_signals.cmd", ); - let (mut autorouter, ..) = invoker.destruct(); + let (mut autorouter, ..) = invoker.dissolve(); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); //common::assert_number_of_conncomps(&mut autorouter, 16); @@ -87,7 +87,7 @@ fn test_tht_3pin_xlr_to_tht_3pin_xlr() { "tests/single_layer/tht_3pin_xlr_to_tht_3pin_xlr/autoroute_all.cmd", ); - let (mut autorouter, ..) = invoker.destruct(); + let (mut autorouter, ..) = invoker.dissolve(); // FIXME: The routing result is pretty bad. common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu");