roadmap/
status.rs

1use serde::Deserialize;
2
3/// Represent the status of a step in a roadmap.
4///
5/// The unknown status allows the user to not specify the status, and
6/// the roadmap to infer it from the structure of the graph. For
7/// example, a step is inferred to be blocked if any of it
8/// dependencies are not finished.
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
11#[serde(rename_all = "lowercase")]
12pub enum Status {
13    Unknown,
14    Goal,
15    Finished,
16    Ready,
17    Next,
18    Blocked,
19}
20
21impl Default for Status {
22    fn default() -> Self {
23        Self::Unknown
24    }
25}
26
27impl Status {
28    pub fn from_text(text: &str) -> Option<Status> {
29        match text {
30            "" => Some(Status::Unknown),
31            "goal" => Some(Status::Goal),
32            "finished" => Some(Status::Finished),
33            "ready" => Some(Status::Ready),
34            "next" => Some(Status::Next),
35            "blocked" => Some(Status::Blocked),
36            _ => None,
37        }
38    }
39}
40
41#[cfg(test)]
42mod test {
43    use super::Status;
44
45    #[test]
46    fn happy_from_text() {
47        assert_eq!(Status::from_text("").unwrap(), Status::Unknown);
48        assert_eq!(Status::from_text("goal").unwrap(), Status::Goal);
49        assert_eq!(Status::from_text("finished").unwrap(), Status::Finished);
50        assert_eq!(Status::from_text("ready").unwrap(), Status::Ready);
51        assert_eq!(Status::from_text("next").unwrap(), Status::Next);
52        assert_eq!(Status::from_text("blocked").unwrap(), Status::Blocked);
53    }
54
55    #[test]
56    fn sad_from_text() {
57        let x = Status::from_text("x");
58        assert_eq!(x, None);
59    }
60}