This commit is contained in:
darko.deuric 2022-08-05 14:12:22 +02:00
parent b265cc0b19
commit 0171326c5a
2 changed files with 16 additions and 6 deletions

View File

@ -2,13 +2,15 @@
// Address all the TODOs to make the tests pass!
// Execute `rustlings hint structs1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
struct ColorClassicStruct {
// TODO: Something goes here
red: u32,
green: u32,
blue: u32,
}
struct ColorTupleStruct(/* TODO: Something goes here */);
struct ColorTupleStruct(u32, u32, u32);
#[derive(Debug)]
struct UnitLikeStruct;
@ -20,7 +22,11 @@ mod tests {
#[test]
fn classic_c_structs() {
// TODO: Instantiate a classic c struct!
// let green =
let green = ColorClassicStruct{
red: 0,
blue: 0,
green: 255
};
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
@ -30,7 +36,7 @@ mod tests {
#[test]
fn tuple_structs() {
// TODO: Instantiate a tuple struct!
// let green =
let green = (0, 255, 0);
assert_eq!(green.0, 0);
assert_eq!(green.1, 255);
@ -40,7 +46,7 @@ mod tests {
#[test]
fn unit_structs() {
// TODO: Instantiate a unit-like struct!
// let unit_like_struct =
let unit_like_struct = UnitLikeStruct;
let message = format!("{:?}s are fun!", unit_like_struct);
assert_eq!(message, "UnitLikeStructs are fun!");

View File

@ -35,7 +35,11 @@ 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: "Hacker in Rust".to_string(),
count: 1,
..order_template
};
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);