mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Allow to derive Parse/ToCss/SpecifiedValueInfo on bitflags
We keep getting this pattern of properties that have a set of joint and disjoint flags, and copy-pasting or writing the same parsing and serialization code in slightly different ways. container-type is one such type, and I think we should have a single way of dealing with this, thus implement deriving for various traits for bitflags, with an attribute that says which flags are single vs mixed. See docs and properties I ported. The remaining ones I left TODOs with, they are a bit trickier but can be ported with some care. Differential Revision: https://phabricator.services.mozilla.com/D142418
This commit is contained in:
parent
19a43aa7da
commit
f30837baf1
8 changed files with 222 additions and 312 deletions
|
@ -44,6 +44,29 @@ use std::fmt::{self, Write};
|
|||
/// * `#[css(represents_keyword)]` can be used on bool fields in order to
|
||||
/// serialize the field name if the field is true, or nothing otherwise. It
|
||||
/// also collects those keywords for `SpecifiedValueInfo`.
|
||||
/// * `#[css(bitflags(single="", mixed="", validate="")]` can be used to derive
|
||||
/// parse / serialize / etc on bitflags. The rules for parsing bitflags are
|
||||
/// the following:
|
||||
///
|
||||
/// * `single` flags can only appear on their own. It's common that bitflags
|
||||
/// properties at least have one such value like `none` or `auto`.
|
||||
/// * `mixed` properties can appear mixed together, but not along any other
|
||||
/// flag that shares a bit with itself. For example, if you have three
|
||||
/// bitflags like:
|
||||
///
|
||||
/// FOO = 1 << 0;
|
||||
/// BAR = 1 << 1;
|
||||
/// BAZ = 1 << 2;
|
||||
/// BAZZ = BAR | BAZ;
|
||||
///
|
||||
/// Then the following combinations won't be valid:
|
||||
///
|
||||
/// * foo foo: (every flag shares a bit with itself)
|
||||
/// * bar bazz: (bazz shares a bit with bar)
|
||||
///
|
||||
/// But `bar baz` will be valid, as they don't share bits, and so would
|
||||
/// `foo` with any other flag, or `bazz` on its own.
|
||||
///
|
||||
/// * finally, one can put `#[css(derive_debug)]` on the whole type, to
|
||||
/// implement `Debug` by a single call to `ToCss::to_css`.
|
||||
pub trait ToCss {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue