From 1a3fa68cd061433378896c0ad4e27a464757cb05 Mon Sep 17 00:00:00 2001 From: Brad Clawsie Date: Sun, 1 Nov 2026 11:31:20 -0600 Subject: feat: ex3_2 commit 1dec16ba2b11bdc3fc31bfbfeeca0751b778ed3b Author: Brad Clawsie Date: Sun Nov 1 11:30:57 2026 -0600 feat: ex3_2 --- ex3_2/Cargo.lock | 7 +++++++ ex3_2/Cargo.toml | 6 ++++++ ex3_2/src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 ex3_2/Cargo.lock create mode 100644 ex3_2/Cargo.toml create mode 100644 ex3_2/src/main.rs diff --git a/ex3_2/Cargo.lock b/ex3_2/Cargo.lock new file mode 100644 index 0000000..571c14b --- /dev/null +++ b/ex3_2/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ex3_2" +version = "0.1.0" diff --git a/ex3_2/Cargo.toml b/ex3_2/Cargo.toml new file mode 100644 index 0000000..0d79254 --- /dev/null +++ b/ex3_2/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ex3_2" +version = "0.1.0" +edition = "2024" + +[dependencies] 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"); + } +} + -- cgit v1.2.3