/// The different states a Task can go through during its lifetime. pub enum TaskState { /// The state that every Task starts in. /// /// The STARTING state can only lead to the processing state. Starting, /// The state that each Task is in while it is actually /// being process and running on a thread. /// /// The PROCESSING state can only lead to WAITING, /// FINISHED, or UNKNOWN states. Processing, /// The state a Task is in while it is waiting for child /// tasks to switch to the FINISHED state. /// /// The WAITING state can only lead to the DONE_WAITING /// and UNKNOWN states. Waiting, /// The state a Task is in once it is done processing /// child tasks, but prior to going back to the PROCESSING state. /// /// The DONE_WAITING state can only lead to the PROCESSING /// and UNKNOWN states. DoneWaiting, /// The state a Task will be in when it is FINISHED processing /// and ready to be destroyed. /// /// The FINISHED state cannot lead to any states and shows that the /// task is completed. Finished, /// The state a Task will be placed in if it is detected to be /// in an inproper state during its lifetime. Unknown } impl TaskState { /// Get a str representation of this variant. pub fn to_str(&self) -> &'static str { match *self { TaskState::Starting => { "Starting" } TaskState::Waiting => { "Waiting" } TaskState::DoneWaiting => { "DoneWaiting" } TaskState::Processing => { "Processing" } TaskState::Finished => { "Finished" } TaskState::Unknown => { "Unknown" } } } /// Get a String representation of this variant. pub fn to_string(&self) -> String { String::from(self.to_str()) } } impl ::std::fmt::Debug for TaskState { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{}", self.to_str()) } } impl ::std::fmt::Display for TaskState { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{}", self.to_str()) } }