taskboard_core_lib/
task.rs

1#![deny(missing_docs)]
2use serde::{Deserialize, Serialize};
3
4/// A task represents a single job.
5/// Usage example:
6/// ```
7/// use taskboard_core_lib::Task;
8/// let task_1 = Task::new(1, "Learn rust");
9/// let task_2 = Task::new(2, "Learn K8S");
10/// assert_ne!(task_1, task_2);
11/// ```
12#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
13pub struct Task {
14    /// A number used for identifying tasks within a project
15    pub number: usize,
16    /// The task's title
17    pub title: String,
18    /// The task's current status
19    pub status: Status,
20    /// Remaning work in number of hours, or None if not specified
21    pub remaining_work: Option<u8>,
22}
23
24/// A wrapper type with a list of tasks associated to a project
25#[derive(Clone, Debug, Deserialize, Serialize)]
26pub struct ProjectTasks {
27    /// Name of the related project
28    pub project_name: String,
29    /// All tasks associated with that project
30    pub tasks: Vec<Task>,
31}
32
33/// A tasks status
34#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
35pub enum Status {
36    /// Not doing
37    Todo,
38    /// Currently doing
39    Doing,
40    /// Completed
41    Done,
42}
43
44impl Task {
45    /// Creates a new Task with status Todo
46    pub fn new(number: usize, title: &str) -> Self {
47        Task {
48            number,
49            title: String::from(title),
50            status: Status::Todo,
51            remaining_work: None,
52        }
53    }
54}
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn new_should_set_status_to_todo() {
62        assert_eq!(Task::new(1, "").status, Status::Todo);
63    }
64
65    #[test]
66    fn new_should_not_set_remaining_work() {
67        assert_eq!(Task::new(1, "").remaining_work, None);
68    }
69}