From 9afbc03f686fb84164699b2f3b7e2f252b0f4ffb Mon Sep 17 00:00:00 2001 From: blacktoast Date: Thu, 30 Sep 2021 07:24:05 +0000 Subject: [PATCH] structs clear! --- exercises/structs/structs1.rs | 13 ++++--------- exercises/structs/structs3.rs | 16 ++++++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index aec3a892..be149b6f 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -13,7 +13,9 @@ struct ColorClassicStruct { struct ColorTupleStruct(); #[derive(Debug)] -struct UnitStruct; +struct UnitStruct{ + +} #[cfg(test)] mod tests { @@ -41,9 +43,7 @@ mod tests { #[test] fn unit_structs() { // TODO: Instantiate a unit struct! - let unit_structs ={ - let str=String::from("test"); - }; + let unit_structs:UnitStruct=UnitStruct{}; let message = format!("{:?}s are fun!", unit_structs); assert_eq!(message, "UnitStructs are fun!"); @@ -51,8 +51,3 @@ mod tests { } -fn main() { - let unit_structs =String::from("UnitStruct"); - let message = format!("{:?}s are fun!", unit_structs); - println!("{}",message); -} diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 891de674..b5bd05c0 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -4,7 +4,6 @@ // Make the code compile and the tests pass! // If you have issues execute `rustlings hint structs3` -// I AM NOT DONE #[derive(Debug)] struct Package { @@ -17,7 +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!("Oh no") + panic!("Oh no") } else { return Package { sender_country, @@ -27,12 +26,17 @@ impl Package { } } - fn is_international(&self) -> ??? { - // Something goes here... + fn is_international(&self) -> bool { + if self.sender_country==self.recipient_country{ + false + }else{ + true + } } - fn get_fees(&self, cents_per_gram: i32) -> ??? { + fn get_fees(&self, cents_per_gram: i32) -> i32 { // Something goes here... + cents_per_gram*self.weight_in_grams } } @@ -74,7 +78,7 @@ mod tests { let sender_country = String::from("Spain"); let recipient_country = String::from("Spain"); - let cents_per_gram = ???; + let cents_per_gram = 3; let package = Package::new(sender_country, recipient_country, 1500);