From 566949d4c132b584c8c4a8944c7a848e5bfa29e0 Mon Sep 17 00:00:00 2001 From: Ellen Emilia Anna Zscheile Date: Sat, 29 Mar 2025 22:28:04 +0100 Subject: [PATCH] refactor(interactor): use enum_dispatch for ActivityStepper --- src/interactor/activity.rs | 42 ++------------------------------------ 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/src/interactor/activity.rs b/src/interactor/activity.rs index d16e7f9..ba4a8c7 100644 --- a/src/interactor/activity.rs +++ b/src/interactor/activity.rs @@ -4,6 +4,7 @@ use std::ops::ControlFlow; +use enum_dispatch::enum_dispatch; use geo::Point; use thiserror::Error; @@ -43,6 +44,7 @@ pub enum ActivityError { } /// An activity is either an interaction or an execution +#[enum_dispatch(GetMaybeNavmesh, GetMaybeNavcord, GetGhosts, GetObstacles)] pub enum ActivityStepper { Interaction(InteractionStepper), Execution(ExecutionStepper), @@ -73,46 +75,6 @@ impl Abort> for ActivityStepper { } } -impl GetMaybeNavmesh for ActivityStepper { - /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. - fn maybe_navmesh(&self) -> Option<&Navmesh> { - match self { - ActivityStepper::Interaction(interaction) => interaction.maybe_navmesh(), - ActivityStepper::Execution(execution) => execution.maybe_navmesh(), - } - } -} - -impl GetMaybeNavcord for ActivityStepper { - /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. - fn maybe_navcord(&self) -> Option<&NavcordStepper> { - match self { - ActivityStepper::Interaction(interaction) => interaction.maybe_navcord(), - ActivityStepper::Execution(execution) => execution.maybe_navcord(), - } - } -} - -impl GetGhosts for ActivityStepper { - /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. - fn ghosts(&self) -> &[PrimitiveShape] { - match self { - ActivityStepper::Interaction(interaction) => interaction.ghosts(), - ActivityStepper::Execution(execution) => execution.ghosts(), - } - } -} - -impl GetObstacles for ActivityStepper { - /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. - fn obstacles(&self) -> &[PrimitiveIndex] { - match self { - ActivityStepper::Interaction(interaction) => interaction.obstacles(), - ActivityStepper::Execution(execution) => execution.obstacles(), - } - } -} - /// An ActivityStepper that preserves its status pub struct ActivityStepperWithStatus { activity: ActivityStepper,