diff options
| author | liv <mokou@fastmail.com> | 2023-08-29 10:20:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-29 10:20:36 +0200 |
| commit | 2d1da2ab57080e32725612ffddb82006f47f7f71 (patch) | |
| tree | 77bf791ffb668bd05ce26f60a3153692d396e0ed /exercises | |
| parent | d79984dbda5cab0da778d2af27239e25e5f084a1 (diff) | |
| parent | 9c0581bc0faea12b790e0fa0cafe8d08a5ed028e (diff) | |
Merge pull request #1645 from mo8it/prober-types-structs3
Use u32 instead of i32
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/structs/structs3.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 4851317..7cda5af 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -13,13 +13,15 @@ struct Package { sender_country: String, recipient_country: String, - weight_in_grams: i32, + weight_in_grams: u32, } impl Package { - fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package { - if weight_in_grams <= 0 { - panic!("Can not ship a weightless package.") + fn new(sender_country: String, recipient_country: String, weight_in_grams: u32) -> Package { + if weight_in_grams < 10 { + // This is not how you should handle errors in Rust, + // but we will learn about error handling later. + panic!("Can not ship a package with weight below 10 grams.") } else { Package { sender_country, @@ -33,7 +35,7 @@ impl Package { // Something goes here... } - fn get_fees(&self, cents_per_gram: i32) -> ??? { + fn get_fees(&self, cents_per_gram: u32) -> ??? { // Something goes here... } } @@ -48,7 +50,7 @@ mod tests { let sender_country = String::from("Spain"); let recipient_country = String::from("Austria"); - Package::new(sender_country, recipient_country, -2210); + Package::new(sender_country, recipient_country, 5); } #[test] |
