[WIP] Parse Style from and serialize to CSS syntax
This is an incomplete work in progress, submitted in case someone wants to have a look at the approach.
~This requires and is based on top of https://github.com/DioxusLabs/taffy/pull/459, so consider looking at per-commit diff.~
Objective
Fixes https://github.com/DioxusLabs/taffy/issues/440
TODO: update RELEASES.md.
Context
See discussion in https://github.com/DioxusLabs/taffy/issues/440
Feedback wanted
No proc macro so far, but I’ve made liberal use of private traits and macro_rules! to reduce redundant code and risk of copy-paste errors. Hopefully the code is still approachable.
"unused variable" warnings are deliberate, they represent Style struct fields / CSS properties for which parsing or serialization still needs to be implemented.
FWIW, the fact that cssparser uses proc_macros (and syn/quote) and that we'll be paying that price for this feature anyway, makes me much less averse to using them in this PR. I would be interested to see what that would look like. It would certainly be nice to just add an attribute to the main struct definitions rather than having macro definition. I'm still wary of it's affect on compile times though.
(although I'm also wondering whether cssparser really needs them. Looks to me that it's uses of them are fairly trivial and could easily be replaced with manual MAX_LENGTH implementations along with a CI script to enforce correctness. But I guess most people will have syn somewhere in their dependency tree anyway, so perhaps it's better to just not worry about it?)
cssparser’s proc macros used to do more but they’ve shrunk over time. And I think const fn is powerful enough now that it could replace them entirely, although the diagnostics are worse for invalid (uppercase) input: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c8e590525b1ac8f7304cf2c08394af2f
I tried using those const fns in cssparser existing macro_rules but ran into difficulties with $x: expr v.s. $x: pat. However even if that was overcome, syn is still used both through phf-macros and for the match_byte! macro (which was a build script from when proper proc macros were not stable yet, but that’s changing.)