mirror of
https://github.com/ArthurDanjou/rustlings.git
synced 2026-02-04 13:47:49 +01:00
- Created empty solution files for various exercises in strings, modules, hashmaps, options, error handling, generics, traits, lifetimes, tests, iterators, smart pointers, threads, macros, clippy, conversions, and quizzes. - Each solution file contains a main function with a comment indicating that it will be automatically filled after completing the exercise. - Added a README.md file to provide information about the solutions and their purpose.
51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
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(u8, u8, u8);
|
|
|
|
#[derive(Debug)]
|
|
struct UnitStruct;
|
|
|
|
fn main() {
|
|
// You can optionally experiment here.
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn regular_structs() {
|
|
// TODO: Instantiate a regular struct.
|
|
let green = ColorRegularStruct { red: 0, green: 255, blue: 0 };
|
|
|
|
assert_eq!(green.red, 0);
|
|
assert_eq!(green.green, 255);
|
|
assert_eq!(green.blue, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn tuple_structs() {
|
|
// TODO: Instantiate a tuple struct.
|
|
let green = ColorTupleStruct(0, 255, 0);
|
|
|
|
assert_eq!(green.0, 0);
|
|
assert_eq!(green.1, 255);
|
|
assert_eq!(green.2, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn unit_structs() {
|
|
// TODO: Instantiate a unit struct.
|
|
let unit_struct = UnitStruct;
|
|
let message = format!("{unit_struct:?}s are fun!");
|
|
|
|
assert_eq!(message, "UnitStructs are fun!");
|
|
}
|
|
}
|