mirror of https://codeberg.org/topola/topola.git
refactor: make `Step`'s error an associated type
This was suggested in https://codeberg.org/topola/topola/pulls/79.
This commit is contained in:
parent
0d6a0237a9
commit
a9e42eef17
|
|
@ -87,9 +87,9 @@ impl AutorouteExecutionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus, AutorouterError, ()>
|
||||
for AutorouteExecutionStepper
|
||||
{
|
||||
impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus, ()> for AutorouteExecutionStepper {
|
||||
type Error = AutorouterError;
|
||||
|
||||
fn step(&mut self, autorouter: &mut Autorouter<M>) -> Result<AutorouteStatus, AutorouterError> {
|
||||
let Some(curr_ratline) = self.curr_ratline else {
|
||||
return Ok(AutorouteStatus::Finished);
|
||||
|
|
|
|||
|
|
@ -66,9 +66,11 @@ impl CompareDetoursExecutionStepper {
|
|||
|
||||
// XXX: Do we really need this to be a stepper? We don't use at the moment, as sorting functions
|
||||
// aren't steppable either. It may be useful for debugging later on tho.
|
||||
impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterError, (f64, f64)>
|
||||
impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, (f64, f64)>
|
||||
for CompareDetoursExecutionStepper
|
||||
{
|
||||
type Error = AutorouterError;
|
||||
|
||||
fn step(
|
||||
&mut self,
|
||||
autorouter: &mut Autorouter<M>,
|
||||
|
|
|
|||
|
|
@ -74,7 +74,9 @@ impl ExecutionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl<M: AccessMesadata> Step<Invoker<M>, InvokerStatus, InvokerError, ()> for ExecutionStepper {
|
||||
impl<M: AccessMesadata> Step<Invoker<M>, InvokerStatus, ()> for ExecutionStepper {
|
||||
type Error = InvokerError;
|
||||
|
||||
fn step(&mut self, invoker: &mut Invoker<M>) -> Result<InvokerStatus, InvokerError> {
|
||||
match self.step_catch_err(&mut invoker.autorouter) {
|
||||
Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running),
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ pub enum ActivityStepper {
|
|||
Execution(ExecutionStepper),
|
||||
}
|
||||
|
||||
impl<M: AccessMesadata> Step<ActivityContext<'_, M>, ActivityStatus, ActivityError, ()>
|
||||
for ActivityStepper
|
||||
{
|
||||
impl<M: AccessMesadata> Step<ActivityContext<'_, M>, ActivityStatus, ()> for ActivityStepper {
|
||||
type Error = ActivityError;
|
||||
|
||||
fn step(&mut self, context: &mut ActivityContext<M>) -> Result<ActivityStatus, ActivityError> {
|
||||
match self {
|
||||
ActivityStepper::Interaction(interaction) => {
|
||||
|
|
@ -152,9 +152,11 @@ impl ActivityStepperWithStatus {
|
|||
}
|
||||
}
|
||||
|
||||
impl<M: AccessMesadata> Step<ActivityContext<'_, M>, ActivityStatus, ActivityError, ()>
|
||||
impl<M: AccessMesadata> Step<ActivityContext<'_, M>, ActivityStatus, ()>
|
||||
for ActivityStepperWithStatus
|
||||
{
|
||||
type Error = ActivityError;
|
||||
|
||||
fn step(&mut self, context: &mut ActivityContext<M>) -> Result<ActivityStatus, ActivityError> {
|
||||
let status = self.activity.step(context)?;
|
||||
self.maybe_status = Some(status.clone());
|
||||
|
|
|
|||
|
|
@ -42,7 +42,9 @@ pub enum InteractionStepper {
|
|||
// - interactively moving a footprint.
|
||||
}
|
||||
|
||||
impl Step<InteractionContext, InteractionStatus, InteractionError, ()> for InteractionStepper {
|
||||
impl Step<InteractionContext, InteractionStatus, ()> for InteractionStepper {
|
||||
type Error = InteractionError;
|
||||
|
||||
fn step(
|
||||
&mut self,
|
||||
context: &mut InteractionContext,
|
||||
|
|
|
|||
|
|
@ -203,14 +203,16 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<G, K, R, S: AstarStrategy<G, K, R>>
|
||||
Step<S, AstarStatus<G, K, R>, AstarError, (K, Vec<G::NodeId>, R)> for Astar<G, K>
|
||||
impl<G, K, R, S: AstarStrategy<G, K, R>> Step<S, AstarStatus<G, K, R>, (K, Vec<G::NodeId>, R)>
|
||||
for Astar<G, K>
|
||||
where
|
||||
G: GraphBase,
|
||||
G::NodeId: Eq + Hash,
|
||||
for<'a> &'a G: IntoEdges<NodeId = G::NodeId, EdgeId = G::EdgeId> + MakeEdgeRef,
|
||||
K: Measure + Copy,
|
||||
{
|
||||
type Error = AstarError;
|
||||
|
||||
fn step(&mut self, strategy: &mut S) -> Result<AstarStatus<G, K, R>, AstarError> {
|
||||
if let Some(curr_node) = self.maybe_curr_node {
|
||||
if self.is_probing {
|
||||
|
|
|
|||
|
|
@ -73,9 +73,9 @@ impl RouteStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, R: AccessRules> Step<Router<'a, R>, RouterStatus, AstarError, BandTermsegIndex>
|
||||
for RouteStepper
|
||||
{
|
||||
impl<'a, R: AccessRules> Step<Router<'a, R>, RouterStatus, BandTermsegIndex> for RouteStepper {
|
||||
type Error = AstarError;
|
||||
|
||||
fn step(&mut self, router: &mut Router<R>) -> Result<RouterStatus, AstarError> {
|
||||
let navcorder = Navcorder::new(router.layout_mut());
|
||||
let target = self.astar.graph.destination();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
pub trait Step<C, S: TryInto<O>, E, O> {
|
||||
fn step(&mut self, context: &mut C) -> Result<S, E>;
|
||||
pub trait Step<C, S: TryInto<O>, O> {
|
||||
type Error;
|
||||
|
||||
fn finish(&mut self, context: &mut C) -> Result<O, E> {
|
||||
fn step(&mut self, context: &mut C) -> Result<S, Self::Error>;
|
||||
|
||||
fn finish(&mut self, context: &mut C) -> Result<O, Self::Error> {
|
||||
loop {
|
||||
if let Ok(outcome) = self.step(context)?.try_into() {
|
||||
return Ok(outcome);
|
||||
|
|
|
|||
Loading…
Reference in New Issue