summaryrefslogtreecommitdiff
path: root/exercises/07_structs/structs1.rs
diff options
context:
space:
mode:
Diffstat (limited to 'exercises/07_structs/structs1.rs')
-rwxr-xr-x[-rw-r--r--]exercises/07_structs/structs1.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/exercises/07_structs/structs1.rs b/exercises/07_structs/structs1.rs
index 959c4c6..3da1ce0 100644..100755
--- a/exercises/07_structs/structs1.rs
+++ b/exercises/07_structs/structs1.rs
@@ -1,9 +1,17 @@
struct ColorRegularStruct {
// TODO: Add the fields that the test `regular_structs` expects.
// What types should the fields have? What are the minimum and maximum values for RGB colors?
+ red: i32,
+ green: i32,
+ blue: i32,
}
-struct ColorTupleStruct(/* TODO: Add the fields that the test `tuple_structs` expects */);
+struct ColorTupleStruct(
+ /* TODO: Add the fields that the test `tuple_structs` expects */
+ i32,
+ i32,
+ i32,
+);
#[derive(Debug)]
struct UnitStruct;
@@ -19,7 +27,11 @@ mod tests {
#[test]
fn regular_structs() {
// TODO: Instantiate a regular struct.
- // let green =
+ let green = ColorRegularStruct {
+ red: 0,
+ green: 255,
+ blue: 0,
+ };
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
@@ -29,7 +41,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);
@@ -39,8 +51,9 @@ mod tests {
#[test]
fn unit_structs() {
// TODO: Instantiate a unit struct.
- // let unit_struct =
- let message = format!("{unit_struct:?}s are fun!");
+ #[derive(Debug)]
+ struct UnitStruct;
+ let message = format!("{UnitStruct:?}s are fun!");
assert_eq!(message, "UnitStructs are fun!");
}