Skip to content

Commit 29e7a33

Browse files
committed
update
1 parent ade0692 commit 29e7a33

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

exercises/structs/structs1.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
// Execute `rustlings hint structs1` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
98

109
struct ColorClassicStruct {
10+
red : u32,
11+
green : u32,
12+
blue : u32,
13+
1114
// TODO: Something goes here
1215
}
1316

14-
struct ColorTupleStruct(/* TODO: Something goes here */);
17+
struct ColorTupleStruct(u32,u32,u32);
1518

1619
#[derive(Debug)]
1720
struct UnitLikeStruct;
@@ -24,7 +27,12 @@ mod tests {
2427
fn classic_c_structs() {
2528
// TODO: Instantiate a classic c struct!
2629
// let green =
30+
let green = ColorClassicStruct{
31+
red:0,
32+
green:255,
33+
blue :0,
2734

35+
};
2836
assert_eq!(green.red, 0);
2937
assert_eq!(green.green, 255);
3038
assert_eq!(green.blue, 0);
@@ -34,7 +42,7 @@ mod tests {
3442
fn tuple_structs() {
3543
// TODO: Instantiate a tuple struct!
3644
// let green =
37-
45+
let green = ColorTupleStruct(0,255,0);
3846
assert_eq!(green.0, 0);
3947
assert_eq!(green.1, 255);
4048
assert_eq!(green.2, 0);
@@ -44,6 +52,7 @@ mod tests {
4452
fn unit_structs() {
4553
// TODO: Instantiate a unit-like struct!
4654
// let unit_like_struct =
55+
let unit_like_struct = UnitLikeStruct;
4756
let message = format!("{:?}s are fun!", unit_like_struct);
4857

4958
assert_eq!(message, "UnitLikeStructs are fun!");

exercises/structs/structs2.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Execute `rustlings hint structs2` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
98

109
#[derive(Debug)]
1110
struct Order {
@@ -39,6 +38,11 @@ mod tests {
3938
let order_template = create_order_template();
4039
// TODO: Create your own order using the update syntax and template above!
4140
// let your_order =
41+
let your_order = Order{
42+
name : String::from("Hacker in Rust"),
43+
count : 1,
44+
..order_template
45+
};
4246
assert_eq!(your_order.name, "Hacker in Rust");
4347
assert_eq!(your_order.year, order_template.year);
4448
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);

0 commit comments

Comments
 (0)