solution to exercise 03_07
This commit is contained in:
parent
56075fa40e
commit
1f0823a6a4
@ -11,21 +11,9 @@ pub struct Ticket {
|
||||
|
||||
impl Ticket {
|
||||
pub fn new(title: String, description: String, status: String) -> Ticket {
|
||||
if title.is_empty() {
|
||||
panic!("Title cannot be empty");
|
||||
}
|
||||
if title.len() > 50 {
|
||||
panic!("Title cannot be longer than 50 bytes");
|
||||
}
|
||||
if description.is_empty() {
|
||||
panic!("Description cannot be empty");
|
||||
}
|
||||
if description.len() > 500 {
|
||||
panic!("Description cannot be longer than 500 bytes");
|
||||
}
|
||||
if status != "To-Do" && status != "In Progress" && status != "Done" {
|
||||
panic!("Only `To-Do`, `In Progress`, and `Done` statuses are allowed");
|
||||
}
|
||||
validate_title(&title);
|
||||
validate_description(&description);
|
||||
validate_status(&status);
|
||||
|
||||
Ticket {
|
||||
title,
|
||||
@ -45,6 +33,45 @@ impl Ticket {
|
||||
pub fn status(&self) -> &String {
|
||||
&self.status
|
||||
}
|
||||
|
||||
pub fn set_title(&mut self, title: String) {
|
||||
validate_title(&title);
|
||||
self.title = title;
|
||||
}
|
||||
|
||||
pub fn set_description(&mut self, description: String) {
|
||||
validate_description(&description);
|
||||
self.description = description;
|
||||
}
|
||||
|
||||
pub fn set_status(&mut self, status: String) {
|
||||
validate_status(&status);
|
||||
self.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_title(title: &String) {
|
||||
if title.is_empty() {
|
||||
panic!("Title cannot be empty");
|
||||
}
|
||||
if title.len() > 50 {
|
||||
panic!("Title cannot be longer than 50 bytes");
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_description(description: &String) {
|
||||
if description.is_empty() {
|
||||
panic!("Description cannot be empty");
|
||||
}
|
||||
if description.len() > 500 {
|
||||
panic!("Description cannot be longer than 500 bytes");
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_status(status: &String) {
|
||||
if status != "To-Do" && status != "In Progress" && status != "Done" {
|
||||
panic!("Only `To-Do`, `In Progress`, and `Done` statuses are allowed");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user