summaryrefslogtreecommitdiff
path: root/ex3_2/src
diff options
context:
space:
mode:
authorBrad Clawsie <brad@b7j0c.org>2026-11-01 11:31:20 -0600
committerBrad Clawsie <brad@b7j0c.org>2026-11-01 11:31:20 -0600
commit1a3fa68cd061433378896c0ad4e27a464757cb05 (patch)
treebaeb6d4c029d8ff444264fa82a8524ce63e4e1d6 /ex3_2/src
parent6979a08cf10d8278f3ea34b1caa7281f7abf3619 (diff)
feat: ex3_2
commit 1dec16ba2b11bdc3fc31bfbfeeca0751b778ed3b Author: Brad Clawsie <brad@b7j0c.org> Date: Sun Nov 1 11:30:57 2026 -0600 feat: ex3_2
Diffstat (limited to 'ex3_2/src')
-rw-r--r--ex3_2/src/main.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/ex3_2/src/main.rs b/ex3_2/src/main.rs
new file mode 100644
index 0000000..94c2447
--- /dev/null
+++ b/ex3_2/src/main.rs
@@ -0,0 +1,49 @@
+#[derive(Debug)]
+pub struct Ticket {
+ title: String,
+ description: String,
+ status: String,
+}
+
+impl Ticket {
+ pub fn new(title: &str, description: &str, status: &str) -> Self {
+ if !(status == "To-Do" || status == "In Progress" || status == "Done") {
+ panic!("status not correct");
+ }
+
+ if title.is_empty() || description.is_empty() {
+ panic!("title or description is empty");
+ }
+
+ if title.len() > 50 {
+ panic!("title too long");
+ }
+
+ if description.len() > 500 {
+ panic!("description too long");
+ }
+
+ Self{
+ title: String::from(title),
+ description: String::from(description),
+ status: String::from(status),
+ }
+ }
+}
+
+fn main() {
+ let ticket = Ticket::new("title","desc","Done");
+ println!("{:?}{:?}{:?}", ticket.title, ticket.description, ticket.status);
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::*;
+
+ #[test]
+ #[should_panic(expected="status not correct")]
+ fn t0() {
+ Ticket::new("title","desc","status");
+ }
+}
+