Description
Implement HexColor as a ValueObject in the primitives module.
Spec: #RRGGBB or #RGB, normalised to uppercase
Implementation checklist
Implementation detail
Input / Output
|
Type |
Alias |
| Input |
String |
HexColorInput |
| Output |
String — always 7-character #RRGGBB uppercase |
HexColorOutput |
Normalization
Trim; uppercase; expand 3-digit shorthand to 6-digit form (#F0A → #FF00AA by doubling each hex digit).
Validation
- Must start with
#.
- Remaining characters must be exactly 3 or 6 hexadecimal digits (
0–9, A–F after uppercasing).
Extra methods
r() -> u8 — red channel value (0–255).
g() -> u8 — green channel value (0–255).
b() -> u8 — blue channel value (0–255).
References
Description
Implement
HexColoras aValueObjectin theprimitivesmodule.Spec:
#RRGGBBor#RGB, normalised to uppercaseImplementation checklist
src/primitives/hexcolor.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/primitives/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
StringHexColorInputString— always 7-character#RRGGBBuppercaseHexColorOutputNormalization
Trim; uppercase; expand 3-digit shorthand to 6-digit form (
#F0A→#FF00AAby doubling each hex digit).Validation
#.0–9,A–Fafter uppercasing).Extra methods
r() -> u8— red channel value (0–255).g() -> u8— green channel value (0–255).b() -> u8— blue channel value (0–255).References