Skip to content

Commit 2edc3a6

Browse files
committed
solve structs2 and structs3
1 parent bf015ea commit 2edc3a6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

exercises/structs/structs2.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Execute `rustlings hint structs2` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
9-
108
#[derive(Debug)]
119
struct Order {
1210
name: String,
@@ -38,7 +36,11 @@ mod tests {
3836
fn your_order() {
3937
let order_template = create_order_template();
4038
// TODO: Create your own order using the update syntax and template above!
41-
// let your_order =
39+
let your_order = Order {
40+
name: String::from("Hacker in Rust"),
41+
count: 1,
42+
..order_template
43+
};
4244
assert_eq!(your_order.name, "Hacker in Rust");
4345
assert_eq!(your_order.year, order_template.year);
4446
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);

exercises/structs/structs3.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// Execute `rustlings hint structs3` or use the `hint` watch subcommand for a
88
// hint.
99

10-
// I AM NOT DONE
11-
1210
#[derive(Debug)]
1311
struct Package {
1412
sender_country: String,
@@ -29,12 +27,17 @@ impl Package {
2927
}
3028
}
3129

32-
fn is_international(&self) -> ??? {
30+
fn is_international(&self) -> bool {
3331
// Something goes here...
32+
if self.sender_country == self.recipient_country {
33+
false
34+
} else {
35+
true
36+
}
3437
}
3538

36-
fn get_fees(&self, cents_per_gram: i32) -> ??? {
37-
// Something goes here...
39+
fn get_fees(&self, cents_per_gram: i32) -> i32 {
40+
self.weight_in_grams * cents_per_gram
3841
}
3942
}
4043

0 commit comments

Comments
 (0)