mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-04 01:39:18 +00:00
Add color struct definitions and instantiate structs
This commit is contained in:
parent
778452a921
commit
853394ec14
@ -5,13 +5,15 @@
|
||||
// Execute `rustlings hint structs1` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
struct ColorClassicStruct {
|
||||
red: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
// TODO: Something goes here
|
||||
}
|
||||
|
||||
struct ColorTupleStruct(/* TODO: Something goes here */);
|
||||
struct ColorTupleStruct(u8, u8, u8/* TODO: Something goes here */);
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UnitLikeStruct;
|
||||
@ -23,7 +25,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 +39,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 +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!");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user