Skip to content

Commit

Permalink
solve structs1
Browse files Browse the repository at this point in the history
  • Loading branch information
a08001212 committed Jan 28, 2025
1 parent f23bbf7 commit 9b14bcf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions exercises/structs/structs1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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!");
Expand Down

0 comments on commit 9b14bcf

Please sign in to comment.