Part of #102 — wave 1.
Mini-spec
Goal: accept every colour and length form an author would reasonably write, and fail loudly on the rest instead of silently rendering black or zero.
Invariants
- No colour string ever resolves to an unintended
SColor::BLACK. Either it parses, or it is surfaced as an error.
- No length string ever silently resolves to
0px.
parse_hex_color keeps its current infallible signature so existing call sites are untouched.
Frozen contract (from #102) — this workstream owns and must expose exactly:
pub fn parse_css_color(input: &str) -> Option<(u8, u8, u8, u8)>
Out of scope: wiring a validation-time error for unresolved colours (L4 consumes this API), gradients.
Acceptance
#fff, #FFF, #ffff, #ffffff, #ffffffff all parse.
rgb(255,255,255), rgba(255,255,255,0.5), hsl(...), hsla(...) parse, with and without spaces.
- The CSS named-colour set is supported (currently 11 names are hardcoded at
paint_pass.rs:1338-1352).
- An unresolvable colour is reported, not silently blackened.
units.rs:139-141 / 163-165 no longer fold an unparseable length into Px(0.0) without a signal.
- Unit tests cover each accepted form and at least three rejected ones.
Files: crates/rustmotion-core/src/engine/renderer/colors.rs, crates/rustmotion-core/src/engine/paint_pass.rs, crates/rustmotion-core/src/css/units.rs
Verify
rtk cargo test -p rustmotion-core
rtk cargo build --release
Part of #102 — wave 1.
Mini-spec
Goal: accept every colour and length form an author would reasonably write, and fail loudly on the rest instead of silently rendering black or zero.
Invariants
SColor::BLACK. Either it parses, or it is surfaced as an error.0px.parse_hex_colorkeeps its current infallible signature so existing call sites are untouched.Frozen contract (from #102) — this workstream owns and must expose exactly:
Out of scope: wiring a validation-time error for unresolved colours (L4 consumes this API), gradients.
Acceptance
#fff,#FFF,#ffff,#ffffff,#ffffffffall parse.rgb(255,255,255),rgba(255,255,255,0.5),hsl(...),hsla(...)parse, with and without spaces.paint_pass.rs:1338-1352).units.rs:139-141/163-165no longer fold an unparseable length intoPx(0.0)without a signal.Files:
crates/rustmotion-core/src/engine/renderer/colors.rs,crates/rustmotion-core/src/engine/paint_pass.rs,crates/rustmotion-core/src/css/units.rsVerify