2019-10-21 12:23:06 +00:00
|
|
|
// structs2.rs
|
2023-05-29 17:39:08 +00:00
|
|
|
//
|
2019-10-21 12:23:06 +00:00
|
|
|
// Address all the TODOs to make the tests pass!
|
2023-05-29 17:39:08 +00:00
|
|
|
//
|
|
|
|
// Execute `rustlings hint structs2` or use the `hint` watch subcommand for a
|
|
|
|
// hint.
|
2019-10-21 12:23:06 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Order {
|
|
|
|
name: String,
|
|
|
|
year: u32,
|
|
|
|
made_by_phone: bool,
|
|
|
|
made_by_mobile: bool,
|
|
|
|
made_by_email: bool,
|
|
|
|
item_number: u32,
|
|
|
|
count: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_order_template() -> Order {
|
|
|
|
Order {
|
|
|
|
name: String::from("Bob"),
|
|
|
|
year: 2019,
|
|
|
|
made_by_phone: false,
|
|
|
|
made_by_mobile: false,
|
|
|
|
made_by_email: true,
|
|
|
|
item_number: 123,
|
|
|
|
count: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn your_order() {
|
|
|
|
let order_template = create_order_template();
|
|
|
|
// TODO: Create your own order using the update syntax and template above!
|
2024-01-29 03:02:06 +00:00
|
|
|
let your_order = Order {
|
|
|
|
name: "Hacker in Rust".to_string(),
|
|
|
|
count: 1,
|
|
|
|
..order_template
|
|
|
|
};
|
2019-10-21 12:23:06 +00:00
|
|
|
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);
|
|
|
|
assert_eq!(your_order.made_by_mobile, order_template.made_by_mobile);
|
|
|
|
assert_eq!(your_order.made_by_email, order_template.made_by_email);
|
|
|
|
assert_eq!(your_order.item_number, order_template.item_number);
|
|
|
|
assert_eq!(your_order.count, 1);
|
|
|
|
}
|
|
|
|
}
|