Skip to content

Commit

Permalink
finish structs1
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-ing committed Jan 18, 2025
1 parent 871308d commit 048fa8f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions exercises/structs/structs1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

struct ColorClassicStruct {
// TODO: Something goes here
red:i32,
green:i32,
blue:i32
}

struct ColorTupleStruct(/* TODO: Something goes here */);
struct ColorTupleStruct(i32,i32,i32);

#[derive(Debug)]
struct UnitLikeStruct;
Expand All @@ -24,7 +27,11 @@ mod tests {
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);
assert_eq!(green.blue, 0);
Expand All @@ -33,8 +40,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);
assert_eq!(green.2, 0);
Expand All @@ -43,7 +49,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 048fa8f

Please sign in to comment.