mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-04 17:23:36 +02:00
Progress: finished primitive types, vecs, movesematics. progress structs
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
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: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
}
|
||||
|
||||
struct ColorTupleStruct(/* TODO: Add the fields that the test `tuple_structs` expects */);
|
||||
struct ColorTupleStruct(u8, u8, u8);
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UnitStruct;
|
||||
@@ -20,7 +23,11 @@ mod tests {
|
||||
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);
|
||||
assert_eq!(green.blue, 0);
|
||||
@@ -30,7 +37,7 @@ mod tests {
|
||||
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);
|
||||
@@ -39,7 +46,7 @@ mod tests {
|
||||
#[test]
|
||||
fn unit_structs() {
|
||||
// TODO: Instantiate a unit struct.
|
||||
// let unit_struct =
|
||||
let unit_struct = UnitStruct;
|
||||
let message = format!("{unit_struct:?}s are fun!");
|
||||
|
||||
assert_eq!(message, "UnitStructs are fun!");
|
||||
|
||||
@@ -36,6 +36,12 @@ mod tests {
|
||||
// TODO: Create your own order using the update syntax and template above!
|
||||
// let your_order =
|
||||
|
||||
let your_order = Order {
|
||||
name: "Hacker in Rust".to_string(),
|
||||
count: 1,
|
||||
..order_template
|
||||
};
|
||||
|
||||
assert_eq!(your_order.name, "Hacker in Rust");
|
||||
assert_eq!(your_order.year, order_template.year);
|
||||
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
||||
|
||||
Reference in New Issue
Block a user