tdo_core/
todo.rs

1//! Implementation of a single Todo item.
2
3/// Data Structure for a simple todo.
4///
5/// A `Todo` item is the atomic unit within the `tdo` microcosm.
6/// It represents a single todo or task, which is identified by an ID.
7/// Information about its state (_done_ or _undone_) can be derived from
8/// the data structure as well as the title of the todo item.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Todo {
11    /// Unique identifier for every Todo.
12    pub id: u32,
13    /// Title of the todo.
14    pub name: String,
15    /// Status of the todo.
16    pub done: bool,
17    /// Optional GitHub issue.
18    pub github: Option<GitHub>,
19}
20
21
22impl Todo {
23    /// Constructor. Creates a new Todo item.
24    pub fn new(id: u32, name: &str, github: Option<GitHub>) -> Todo {
25        Todo {
26            id: id,
27            name: name.to_string(),
28            done: false,
29            github: github,
30        }
31    }
32
33    /// Edit the title of a given Todo.
34    pub fn edit(&mut self, new_name: &str) {
35        self.name = new_name.to_string();
36    }
37
38    /// Set the status of a Todo item to _done_.
39    pub fn set_done(&mut self) {
40        self.done = true;
41    }
42
43    /// Mark a todo item as _undone_.
44    pub fn set_undone(&mut self) {
45        self.done = false;
46    }
47}
48
49/// Data Structure for a represented Github issue in an todo.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct GitHub {
52    /// Name of the repository (owner/repo).
53    pub repo: String,
54    /// Number of the issue.
55    pub issue_number: u32,
56}
57
58impl GitHub {
59    /// Constructor. Creates a new GitHub item.
60    pub fn new(repo: &str, issue_number: u32) -> GitHub {
61        GitHub {
62            repo: repo.to_owned(),
63            issue_number: issue_number,
64        }
65    }
66}
67
68/// Data Structure to parse responses from the Github API.
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct GHIssueResponse {
71    /// Repository URL.
72    pub url: String,
73    /// Issue number.
74    pub number: u32,
75    /// Current state of the Issue.
76    pub state: String,
77    /// Title of the Issue.
78    pub title: String,
79}