13
13
struct Package {
14
14
sender_country : String ,
15
15
recipient_country : String ,
16
- weight_in_grams : i32 ,
16
+ weight_in_grams : u32 ,
17
17
}
18
18
19
19
impl Package {
20
- fn new ( sender_country : String , recipient_country : String , weight_in_grams : i32 ) -> Package {
21
- if weight_in_grams <= 0 {
22
- panic ! ( "Can not ship a weightless package." )
20
+ fn new ( sender_country : String , recipient_country : String , weight_in_grams : u32 ) -> Package {
21
+ if weight_in_grams < 10 {
22
+ // This is not how you should handle errors in Rust,
23
+ // but we will learn about error handling later.
24
+ panic ! ( "Can not ship a package with weight below 10 grams." )
23
25
} else {
24
26
Package {
25
27
sender_country,
@@ -33,7 +35,7 @@ impl Package {
33
35
// Something goes here...
34
36
}
35
37
36
- fn get_fees ( & self , cents_per_gram : i32 ) -> ??? {
38
+ fn get_fees ( & self , cents_per_gram : u32 ) -> ??? {
37
39
// Something goes here...
38
40
}
39
41
}
@@ -48,7 +50,7 @@ mod tests {
48
50
let sender_country = String :: from ( "Spain" ) ;
49
51
let recipient_country = String :: from ( "Austria" ) ;
50
52
51
- Package :: new ( sender_country, recipient_country, - 2210 ) ;
53
+ Package :: new ( sender_country, recipient_country, 5 ) ;
52
54
}
53
55
54
56
#[ test]
0 commit comments