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
//! Types for manipulating jobs.

use std::fmt::{ Display, Formatter, Result as FmtResult };

/// This is received in responses from the RING server.
/// Indicates what phase a specific job is currently in.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum JobStatus {
    /// The hob is in progress.
    #[serde(rename = "db")]
    InProgress,
    /// Part of the job has been completed and some of the results are available.
    /// This is typically returned when the job involves performing an MSA,
    /// and the rest of the computation is done but PSIBLAST is still running.
    #[serde(rename = "partial")]
    Partial,
    /// The job has completed successfully, results are ready to retrieve.
    #[serde(rename = "complete")]
    Complete,
    /// The job has encountered an error and no results are available.
    #[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",
        })
    }
}

/// A RING Job ID.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct JobId(String);

impl JobId {
    /// Returns the string representation of the job ID.
    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())
    }
}