Skip to content

Commit 08bd101

Browse files
committed
ignore re-entrant transitions and rework tests
1 parent e520097 commit 08bd101

6 files changed

Lines changed: 328 additions & 390 deletions

File tree

src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ where
306306

307307
/// Attempt to transition the [`StateMachine`] to the target state.
308308
///
309+
/// If the target state is already in the currently active state hierarchy, no
310+
/// transition is made.
311+
///
309312
/// Subject to short circuit transtions (from [`State::enter`] or [`State::exit`]) and initial
310313
/// transitions (from [`State::init`] or [`TopState::init`]).
311314
/// # Example
@@ -334,8 +337,12 @@ where
334337
/// # use example::*;
335338
/// # use example::machine::*;
336339
/// # let mut machine = ExampleMachineBuilder::new(Top).build();
340+
/// // where Bar is a substate of Top:
337341
/// machine.transition(ExampleState::Bar);
338342
/// assert!(matches!(machine.state(), ExampleState::Bar));
343+
///
344+
/// machine.transition(ExampleState::Top);
345+
/// assert!(matches!(machine.state(), ExampleState::Bar));
339346
/// ```
340347
fn transition(&mut self, target: T);
341348

@@ -1803,7 +1810,14 @@ pub mod internal {
18031810
);
18041811
}
18051812

1806-
self.transition_quiet(target, indent);
1813+
if self.state_matches(target) {
1814+
info!(
1815+
"{}\u{02502}Already in {target:?}",
1816+
if indent { "\u{02502}" } else { "" },
1817+
);
1818+
} else {
1819+
self.transition_quiet(target, indent);
1820+
}
18071821

18081822
info!(
18091823
"{}\u{02514}Transition complete",

0 commit comments

Comments
 (0)