Finish solving structs3.rs exercise but have no idea whats going on

This commit is contained in:
Eri Mendz 2021-06-02 13:48:54 +03:00
parent 301e378b4d
commit 7a783fc24e

View file

@ -3,7 +3,7 @@
// exercise we have defined the Package struct and we want to test some logic attached to it,
// make the code compile and the tests pass! If you have issues execute `rustlings hint structs3`
// I AM NOT DONE
// Done June 2/21
#[derive(Debug)]
struct Package {
@ -16,6 +16,7 @@ impl Package {
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
if weight_in_grams <= 0 {
// Something goes here...
panic!()
} else {
return Package {
sender_country,
@ -25,12 +26,16 @@ impl Package {
}
}
fn is_international(&self) -> ??? {
// this function returns bool type
fn is_international(&self) -> bool {
// Something goes here...
&self.sender_country != &self.recipient_country
}
fn get_fees(&self, cents_per_gram: i32) -> ??? {
fn get_fees(&self, cents_per_gram: i32) -> i32 {
// Something goes here...
// add calculation expression here
(&self.weight_in_grams * cents_per_gram + (1000/2)) / 1000
}
}
@ -62,7 +67,7 @@ mod tests {
let sender_country = String::from("Spain");
let recipient_country = String::from("Spain");
let cents_per_gram = ???;
let cents_per_gram = 3000;
let package = Package::new(sender_country, recipient_country, 1500);