Skip to content

Commit

Permalink
Merge pull request rust-lang#1645 from mo8it/prober-types-structs3
Browse files Browse the repository at this point in the history
Use u32 instead of i32
  • Loading branch information
shadows-withal authored Aug 29, 2023
2 parents d79984d + 9c0581b commit 2d1da2a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions exercises/structs/structs3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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...
}
}
Expand All @@ -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]
Expand Down

0 comments on commit 2d1da2a

Please sign in to comment.