summaryrefslogtreecommitdiff
path: root/ex5_6/src/main.rs
blob: 5ca49f268dbda74b5002bd35b08d8a96813b80ce (plain)
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
#[derive(Debug, PartialEq)]
struct Ticket {
    title: String,
    description: String,
    status: Status,
}

#[derive(Debug, PartialEq)]
enum Status {
    ToDo,
    InProgress { assigned_to: String },
    Done,
}

impl Ticket {
    fn new(title: &str, description: &str, status: Status) -> Result<Ticket, String> {
        if title.is_empty() {
            return Err(String::from("title is empty"));
        }
        Ok(
            Ticket {
                title: String::from(title),
                description: String::from(description),
                status,
            }
        )
    }
}

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn t0() {
        assert_eq!(Ticket::new(
            "",
            "d",
            Status::Done,
        ).is_err(), true);
    }
}