pub struct StateHistory {
pub current: Option<TaskState>,
pub transitions: Vec<StateTransition>,
}Expand description
Tracks state transitions for a task
Fields§
§current: Option<TaskState>Current state
transitions: Vec<StateTransition>List of state transitions
Implementations§
Source§impl StateHistory
impl StateHistory
Sourcepub fn with_initial(state: TaskState) -> Self
pub fn with_initial(state: TaskState) -> Self
Create a new state history with initial state
Sourcepub fn transition(&mut self, to: TaskState) -> Option<StateTransition>
pub fn transition(&mut self, to: TaskState) -> Option<StateTransition>
Transition to a new state
Sourcepub fn transition_with_reason(
&mut self,
to: TaskState,
reason: impl Into<String>,
) -> Option<StateTransition>
pub fn transition_with_reason( &mut self, to: TaskState, reason: impl Into<String>, ) -> Option<StateTransition>
Transition to a new state with a reason
Sourcepub fn current_state(&self) -> Option<&TaskState>
pub fn current_state(&self) -> Option<&TaskState>
Get the current state
Sourcepub fn get_transitions(&self) -> &[StateTransition]
pub fn get_transitions(&self) -> &[StateTransition]
Get all transitions
Sourcepub fn last_transition(&self) -> Option<&StateTransition>
pub fn last_transition(&self) -> Option<&StateTransition>
Get the last transition
Sourcepub const fn transition_count(&self) -> usize
pub const fn transition_count(&self) -> usize
Get the number of transitions
Sourcepub fn has_been_in_state(&self, state_name: &str) -> bool
pub fn has_been_in_state(&self, state_name: &str) -> bool
Check if task has ever been in a specific state
Sourcepub fn time_in_state(&self, state_name: &str) -> Option<f64>
pub fn time_in_state(&self, state_name: &str) -> Option<f64>
Get the time spent in a specific state (returns None if never in that state)
Trait Implementations§
Source§impl Clone for StateHistory
impl Clone for StateHistory
Source§fn clone(&self) -> StateHistory
fn clone(&self) -> StateHistory
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StateHistory
impl Debug for StateHistory
Source§impl Default for StateHistory
impl Default for StateHistory
Source§fn default() -> StateHistory
fn default() -> StateHistory
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for StateHistory
impl<'de> Deserialize<'de> for StateHistory
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for StateHistory
impl RefUnwindSafe for StateHistory
impl Send for StateHistory
impl Sync for StateHistory
impl Unpin for StateHistory
impl UnwindSafe for StateHistory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more