mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-04 18:29:29 -05:00
49 lines
909 B
Rust
49 lines
909 B
Rust
struct ColorRegularStruct {
|
|
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() {
|
|
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() {
|
|
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() {
|
|
let unit_struct = UnitStruct;
|
|
let message = format!("{unit_struct:?}s are fun!");
|
|
|
|
assert_eq!(message, "UnitStructs are fun!");
|
|
}
|
|
}
|