use std::fmt::{ Display, Formatter, Result as FmtResult };
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum JobStatus {
#[serde(rename = "db")]
InProgress,
#[serde(rename = "partial")]
Partial,
#[serde(rename = "complete")]
Complete,
#[serde(rename = "error")]
Failed,
}
impl Display for JobStatus {
fn fmt(&self, formatter: &mut Formatter) -> FmtResult {
formatter.pad(match *self {
JobStatus::InProgress => "in progress",
JobStatus::Partial => "partial",
JobStatus::Complete => "complete",
JobStatus::Failed => "failed",
})
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct JobId(String);
impl JobId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<String> for JobId {
fn from(string: String) -> Self {
JobId(string)
}
}
impl From<&str> for JobId {
fn from(string: &str) -> Self {
JobId(string.into())
}
}
impl From<JobId> for String {
fn from(job_id: JobId) -> Self {
job_id.0
}
}
impl AsRef<str> for JobId {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl Display for JobId {
fn fmt(&self, formatter: &mut Formatter) -> FmtResult {
formatter.pad(self.as_str())
}
}