Skip to main content

nucleus/network/
state.rs

1use crate::error::StateTransition;
2
3/// Network state tracking
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum NetworkState {
6    /// No network configured
7    Unconfigured,
8    /// Network is being set up
9    Configuring,
10    /// Network is active
11    Active,
12    /// Network has been torn down
13    Cleaned,
14}
15
16impl StateTransition for NetworkState {
17    fn can_transition_to(&self, next: &NetworkState) -> bool {
18        matches!(
19            (self, next),
20            (NetworkState::Unconfigured, NetworkState::Configuring)
21                | (NetworkState::Configuring, NetworkState::Active)
22                | (NetworkState::Active, NetworkState::Cleaned)
23        )
24    }
25
26    fn is_terminal(&self) -> bool {
27        matches!(self, NetworkState::Cleaned)
28    }
29}