File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
exercises/03_ticket_v1/02_validation/src Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ use std:: thread:: panicking;
2
+
1
3
struct Ticket {
2
4
title : String ,
3
5
description : String ,
@@ -18,7 +20,23 @@ impl Ticket {
18
20
// as well as some `String` methods. Use the documentation of Rust's standard library
19
21
// to find the most appropriate options -> https://doc.rust-lang.org/std/string/struct.String.html
20
22
fn new ( title : String , description : String , status : String ) -> Self {
21
- todo ! ( ) ;
23
+ match status. as_str ( ) {
24
+ "To-Do" | "In Progress" | "Done" => ( ) ,
25
+ _ => panic ! ( "Only `To-Do`, `In Progress`, and `Done` statuses are allowed" ) ,
26
+ }
27
+ if title. is_empty ( ) {
28
+ panic ! ( "Title cannot be empty" )
29
+ }
30
+ if description. is_empty ( ) {
31
+ panic ! ( "Description cannot be empty!" )
32
+ }
33
+ if title. bytes ( ) . count ( ) > 50 {
34
+ panic ! ( "Title cannot be longer than 50 bytes" )
35
+ }
36
+ if description. bytes ( ) . count ( ) > 500 {
37
+ panic ! ( "Description cannot be longer than 500 bytes" )
38
+ }
39
+
22
40
Self {
23
41
title,
24
42
description,
You can’t perform that action at this time.
0 commit comments