Skip to content

Commit

Permalink
finish all struct problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
a08001212 committed Jan 28, 2025
1 parent 9b14bcf commit 8dd6d32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 10 additions & 3 deletions exercises/structs/structs2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Execute `rustlings hint structs2` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

#[derive(Debug)]
struct Order {
Expand All @@ -20,7 +19,7 @@ struct Order {

fn create_order_template() -> Order {
Order {
name: String::from("Bob"),
name: String::from("Hacker in Rust"),
year: 2019,
made_by_phone: false,
made_by_mobile: false,
Expand All @@ -38,7 +37,15 @@ mod tests {
fn your_order() {
let order_template = create_order_template();
// TODO: Create your own order using the update syntax and template above!
// let your_order =
let your_order = Order{
name: String::from("Hacker in Rust"),
year: 2019,
made_by_phone: false,
made_by_mobile: false,
made_by_email: true,
item_number: 123,
count: 1,
};
assert_eq!(your_order.name, "Hacker in Rust");
assert_eq!(your_order.year, order_template.year);
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
Expand Down
10 changes: 4 additions & 6 deletions exercises/structs/structs3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// Execute `rustlings hint structs3` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

#[derive(Debug)]
struct Package {
sender_country: String,
Expand All @@ -29,12 +27,12 @@ impl Package {
}
}

fn is_international(&self) -> ??? {
// Something goes here...
fn is_international(&self) -> bool{
self.sender_country != self.recipient_country
}

fn get_fees(&self, cents_per_gram: i32) -> ??? {
// Something goes here...
fn get_fees(&self, cents_per_gram: i32) -> i32 {
cents_per_gram * self.weight_in_grams
}
}

Expand Down

0 comments on commit 8dd6d32

Please sign in to comment.