mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
structs clear!
This commit is contained in:
parent
d6953d34f4
commit
9afbc03f68
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user