Sriharsha Madala a9444ddc32 MErge with main
2024-05-19 23:02:25 -07:00

48 lines
979 B
Rust

// structs1.rs
//
// Address all the TODOs to make the tests pass!
//
// Execute `rustlings hint structs1` or use the `hint` watch subcommand for a
// hint.
struct ColorClassicStruct<'a> {
name: &'a str,
hex: &'a str,
}
struct ColorTupleStruct<'a> (&'a str, &'a str);
#[derive(Debug)]
struct UnitLikeStruct;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn classic_c_structs() {
let green = ColorClassicStruct {name: "green", hex: "#00FF00"};
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
assert_eq!(green.blue, 0);
}
#[test]
fn tuple_structs() {
let green = ("green", "#00FF00");
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!("{:?}s are fun!", unit_struct);
assert_eq!(message, "UnitLikeStructs are fun!");
}
}