stepper_motion/motor/
state.rs

1//! Motor state type-state markers.
2//!
3//! Uses Rust's type system to enforce valid state transitions at compile time.
4
5/// Motor is idle and ready for commands.
6#[derive(Debug, Clone, Copy, Default)]
7pub struct Idle;
8
9/// Motor is currently executing a move.
10#[derive(Debug, Clone, Copy)]
11pub struct Moving;
12
13/// Motor is executing a homing sequence.
14#[derive(Debug, Clone, Copy)]
15pub struct Homing;
16
17/// Motor encountered an error and needs recovery.
18#[derive(Debug, Clone, Copy)]
19pub struct Fault;
20
21/// Trait for motor states.
22pub trait MotorState: private::Sealed {}
23
24impl MotorState for Idle {}
25impl MotorState for Moving {}
26impl MotorState for Homing {}
27impl MotorState for Fault {}
28
29mod private {
30    pub trait Sealed {}
31    impl Sealed for super::Idle {}
32    impl Sealed for super::Moving {}
33    impl Sealed for super::Homing {}
34    impl Sealed for super::Fault {}
35}
36
37/// State name for display/debugging.
38pub trait StateName {
39    /// Get the state name as a static string.
40    fn name() -> &'static str;
41}
42
43impl StateName for Idle {
44    fn name() -> &'static str {
45        "Idle"
46    }
47}
48
49impl StateName for Moving {
50    fn name() -> &'static str {
51        "Moving"
52    }
53}
54
55impl StateName for Homing {
56    fn name() -> &'static str {
57        "Homing"
58    }
59}
60
61impl StateName for Fault {
62    fn name() -> &'static str {
63        "Fault"
64    }
65}