diff options
| author | Brad Clawsie <brad@b7j0c.org> | 2026-11-04 14:19:24 -0600 |
|---|---|---|
| committer | Brad Clawsie <brad@b7j0c.org> | 2026-11-04 14:19:24 -0600 |
| commit | 92142fcea7c057f19c7dae1912b6d4a79fd8e8a4 (patch) | |
| tree | a98d45bfcc36b8de40753c69de5aa0fa78e9d0df /ex5_3/src | |
| parent | 52a5b942c1637e7c12fdf18b1ce187b1911dbc47 (diff) | |
feat: ex5_3
commit ce2b679cb320e519eac8cf29850119af10e0a2a7
Author: Brad Clawsie <brad@b7j0c.org>
Date: Wed Nov 4 14:19:10 2026 -0600
feat: ex5_3
Diffstat (limited to 'ex5_3/src')
| -rw-r--r-- | ex5_3/src/main.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ex5_3/src/main.rs b/ex5_3/src/main.rs new file mode 100644 index 0000000..353a3e4 --- /dev/null +++ b/ex5_3/src/main.rs @@ -0,0 +1,56 @@ +#[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 assigned_to(&self) -> String { + match self.status { + Status::InProgress { ref assigned_to } => { + assigned_to.clone() + } + _ => panic!("not in progress") + } + } +} + +fn main() { + println!("Hello, world!"); +} + +#[cfg(test)] +mod tests { + use crate::*; + + #[test] + fn t0() { + let t = Ticket{ + title: String::from("t"), + description: String::from("d"), + status: Status::InProgress{ + assigned_to: String::from("at") + }, + }; + assert_eq!(t.assigned_to(), "at"); + } + + #[test] + #[should_panic(expected = "not in progress")] + fn t1 () { + let t = Ticket{ + title: String::from("t"), + description: String::from("d"), + status: Status::Done, + }; + _ = t.assigned_to(); + } +} |
