mirror of
https://github.com/notohh/rustlings.git
synced 2024-10-30 08:49:12 -04:00
Merge pull request #1645 from mo8it/prober-types-structs3
Use u32 instead of i32
This commit is contained in:
commit
2d1da2ab57
1 changed files with 8 additions and 6 deletions
|
@ -13,13 +13,15 @@
|
||||||
struct Package {
|
struct Package {
|
||||||
sender_country: String,
|
sender_country: String,
|
||||||
recipient_country: String,
|
recipient_country: String,
|
||||||
weight_in_grams: i32,
|
weight_in_grams: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Package {
|
impl Package {
|
||||||
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
fn new(sender_country: String, recipient_country: String, weight_in_grams: u32) -> Package {
|
||||||
if weight_in_grams <= 0 {
|
if weight_in_grams < 10 {
|
||||||
panic!("Can not ship a weightless package.")
|
// 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 {
|
} else {
|
||||||
Package {
|
Package {
|
||||||
sender_country,
|
sender_country,
|
||||||
|
@ -33,7 +35,7 @@ impl Package {
|
||||||
// Something goes here...
|
// Something goes here...
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fees(&self, cents_per_gram: i32) -> ??? {
|
fn get_fees(&self, cents_per_gram: u32) -> ??? {
|
||||||
// Something goes here...
|
// Something goes here...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +50,7 @@ mod tests {
|
||||||
let sender_country = String::from("Spain");
|
let sender_country = String::from("Spain");
|
||||||
let recipient_country = String::from("Austria");
|
let recipient_country = String::from("Austria");
|
||||||
|
|
||||||
Package::new(sender_country, recipient_country, -2210);
|
Package::new(sender_country, recipient_country, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue