summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ex5_3/Cargo.lock7
-rw-r--r--ex5_3/Cargo.toml6
-rw-r--r--ex5_3/src/main.rs56
3 files changed, 69 insertions, 0 deletions
diff --git a/ex5_3/Cargo.lock b/ex5_3/Cargo.lock
new file mode 100644
index 0000000..22bc25c
--- /dev/null
+++ b/ex5_3/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "ex5_3"
+version = "0.1.0"
diff --git a/ex5_3/Cargo.toml b/ex5_3/Cargo.toml
new file mode 100644
index 0000000..fcfb421
--- /dev/null
+++ b/ex5_3/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "ex5_3"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
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();
+ }
+}