refactor: destruct with `.dissolve()` autogenerated with `derive-getters` crate

Introduces `derive-getters` as a dependency.
This commit is contained in:
Mikolaj Wielgus 2024-10-11 16:54:53 +02:00
parent 3766ade270
commit bdc021cb6e
4 changed files with 11 additions and 15 deletions

View File

@ -37,8 +37,9 @@ rstar = "0.12"
petgraph = "0.6.5" petgraph = "0.6.5"
spade = "2.12.1" spade = "2.12.1"
serde_json = "1.0" serde_json = "1.0"
enum_dispatch = "0.3.13"
contracts-try = "0.7" contracts-try = "0.7"
enum_dispatch = "0.3.13"
derive-getters = "0.5.0"
bimap = "0.6.3" bimap = "0.6.3"
log = "0.4" log = "0.4"
utf8-chars = "3.0.4" utf8-chars = "3.0.4"

View File

@ -2,6 +2,7 @@
//! Handles error scenarios related to command history, maintaining lists of executed //! Handles error scenarios related to command history, maintaining lists of executed
//! and undone commands for easy navigation. //! and undone commands for easy navigation.
use derive_getters::Dissolve;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
@ -15,7 +16,7 @@ pub enum HistoryError {
NoNextCommand, NoNextCommand,
} }
#[derive(Debug, Default, Clone, Serialize, Deserialize)] #[derive(Debug, Default, Clone, Dissolve, Serialize, Deserialize)]
pub struct History { pub struct History {
done: Vec<Command>, done: Vec<Command>,
undone: Vec<Command>, undone: Vec<Command>,
@ -26,10 +27,6 @@ impl History {
Self::default() Self::default()
} }
pub fn destruct(self) -> (Vec<Command>, Vec<Command>) {
(self.done, self.undone)
}
pub fn do_(&mut self, command: Command) { pub fn do_(&mut self, command: Command) {
self.done.push(command); self.done.push(command);
} }

View File

@ -3,6 +3,7 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use contracts_try::debug_requires; use contracts_try::debug_requires;
use derive_getters::Dissolve;
use enum_dispatch::enum_dispatch; use enum_dispatch::enum_dispatch;
use thiserror::Error; use thiserror::Error;
@ -69,6 +70,7 @@ impl TryInto<()> for InvokerStatus {
} }
} }
#[derive(Dissolve)]
pub struct Invoker<M: AccessMesadata> { pub struct Invoker<M: AccessMesadata> {
pub(super) autorouter: Autorouter<M>, pub(super) autorouter: Autorouter<M>,
pub(super) history: History, pub(super) history: History,
@ -88,10 +90,6 @@ impl<M: AccessMesadata> Invoker<M> {
} }
} }
pub fn destruct(self) -> (Autorouter<M>, History, Option<Command>) {
(self.autorouter, self.history, self.ongoing_command)
}
//#[debug_requires(self.ongoing_command.is_none())] //#[debug_requires(self.ongoing_command.is_none())]
pub fn execute(&mut self, command: Command) -> Result<(), InvokerError> { pub fn execute(&mut self, command: Command) -> Result<(), InvokerError> {
let mut execute = self.execute_stepper(command)?; let mut execute = self.execute_stepper(command)?;
@ -193,7 +191,7 @@ impl<M: AccessMesadata> Invoker<M> {
#[debug_requires(self.ongoing_command.is_none())] #[debug_requires(self.ongoing_command.is_none())]
pub fn replay(&mut self, history: History) { pub fn replay(&mut self, history: History) {
let (done, undone) = history.destruct(); let (done, undone) = history.dissolve();
for command in done { for command in done {
self.execute(command); self.execute(command);

View File

@ -19,7 +19,7 @@ fn test_0603_breakout() {
"tests/single_layer/0603_breakout/autoroute_all.cmd", "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_single_layer_groundless_autoroute(&mut autorouter, "F.Cu");
//common::assert_number_of_conncomps(&mut autorouter, 2); //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", "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_single_layer_groundless_autoroute(&mut autorouter, "F.Cu");
//common::assert_number_of_conncomps(&mut autorouter, 4); //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", "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_single_layer_groundless_autoroute(&mut autorouter, "F.Cu");
//common::assert_number_of_conncomps(&mut autorouter, 16); //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", "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. // FIXME: The routing result is pretty bad.
common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu");