From 35cd179438aaae1b08681e6e03c88de9be21a286 Mon Sep 17 00:00:00 2001 From: szl Date: Sun, 1 Dec 2024 16:35:00 +0800 Subject: [PATCH] solve structs1 --- exercises/structs/structs1.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index 5fa5821c5..5213bb863 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -5,13 +5,14 @@ // Execute `rustlings hint structs1` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE struct ColorClassicStruct { - // TODO: Something goes here + pub red: i32, + pub green: i32, + pub blue: i32, } -struct ColorTupleStruct(/* TODO: Something goes here */); +struct ColorTupleStruct(i32,i32,i32); #[derive(Debug)] struct UnitLikeStruct; @@ -23,7 +24,11 @@ mod tests { #[test] fn classic_c_structs() { // TODO: Instantiate a classic c struct! - // let green = + let green =ColorClassicStruct{ + red: 0, + green: 255, + blue: 0 + }; assert_eq!(green.red, 0); assert_eq!(green.green, 255); @@ -33,7 +38,7 @@ mod tests { #[test] fn tuple_structs() { // TODO: Instantiate a tuple struct! - // let green = + let green =ColorTupleStruct(0,255,0); assert_eq!(green.0, 0); assert_eq!(green.1, 255); @@ -43,7 +48,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!");