structs clear!

This commit is contained in:
blacktoast 2021-09-30 07:24:05 +00:00
parent d6953d34f4
commit 9afbc03f68
2 changed files with 14 additions and 15 deletions

View File

@ -13,7 +13,9 @@ struct ColorClassicStruct {
struct ColorTupleStruct(); struct ColorTupleStruct();
#[derive(Debug)] #[derive(Debug)]
struct UnitStruct; struct UnitStruct{
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -41,9 +43,7 @@ mod tests {
#[test] #[test]
fn unit_structs() { fn unit_structs() {
// TODO: Instantiate a unit struct! // TODO: Instantiate a unit struct!
let unit_structs ={ let unit_structs:UnitStruct=UnitStruct{};
let str=String::from("test");
};
let message = format!("{:?}s are fun!", unit_structs); let message = format!("{:?}s are fun!", unit_structs);
assert_eq!(message, "UnitStructs are fun!"); 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);
}

View File

@ -4,7 +4,6 @@
// Make the code compile and the tests pass! // Make the code compile and the tests pass!
// If you have issues execute `rustlings hint structs3` // If you have issues execute `rustlings hint structs3`
// I AM NOT DONE
#[derive(Debug)] #[derive(Debug)]
struct Package { struct Package {
@ -17,7 +16,7 @@ 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: i32) -> Package {
if weight_in_grams <= 0 { if weight_in_grams <= 0 {
// Something goes here... // Something goes here...
// panic!("Oh no") panic!("Oh no")
} else { } else {
return Package { return Package {
sender_country, sender_country,
@ -27,12 +26,17 @@ impl Package {
} }
} }
fn is_international(&self) -> ??? { fn is_international(&self) -> bool {
// Something goes here... 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... // Something goes here...
cents_per_gram*self.weight_in_grams
} }
} }
@ -74,7 +78,7 @@ mod tests {
let sender_country = String::from("Spain"); let sender_country = String::from("Spain");
let recipient_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); let package = Package::new(sender_country, recipient_country, 1500);