diff --git a/src/task_state.rs b/src/task_state.rs index 10f4c11..bd39ea7 100644 --- a/src/task_state.rs +++ b/src/task_state.rs @@ -38,3 +38,68 @@ pub enum TaskState /// 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()) + } +} + diff --git a/src/thread_state.rs b/src/thread_state.rs index 7a5f04d..36e0607 100644 --- a/src/thread_state.rs +++ b/src/thread_state.rs @@ -14,3 +14,57 @@ pub enum ThreadState /// Finished } + + + +impl ThreadState +{ + /// Get a str representation of this variant. + pub fn to_str(&self) -> &'static str + { + match *self + { + ThreadState::Starting => + { + "Starting" + } + + ThreadState::Idle => + { + "Idle" + } + + ThreadState::Processing => + { + "Processing" + } + + ThreadState::Finished => + { + "Finished" + } + } + } + + /// Get a String representation of this variant. + pub fn to_string(&self) -> String + { + String::from(self.to_str()) + } +} + +impl ::std::fmt::Debug for ThreadState +{ + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result + { + write!(f, "{}", self.to_str()) + } +} + +impl ::std::fmt::Display for ThreadState +{ + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result + { + write!(f, "{}", self.to_str()) + } +}