1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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())
}
}