pub fn derive(input: DeriveInput) -> TokenStreamExpand description
Derive implementation of the ToTyped trait.
This derive supports both enums and structs:
-
Enums
-
Pure keyword enums: Enums made up entirely of unit variants (e.g.
enum Visibility { Visible, Hidden, Collapse }). In this case, the derive optimizes by delegating toToCssonce for the whole value, then wrapping the result inTypedValue::Keyword. -
Mixed enums with unit variants: Enums that contain both unit variants (keywords) and data-carrying variants. The derive generates a
matchimplementation where unit variants are reified asTypedValue::Keyword, and fielded variants may be reified by calling.to_typed()on their inner values when thederive_fieldsattribute is enabled. Otherwise, those variants returnNone.
-
-
Structs
- Structs are handled similarly to data-carrying variants in mixed enums.
When
derive_fieldsis enabled and the type is not marked as a bitflags type,.to_typed()may be generated for their inner value; otherwise, they returnNone.
- Structs are handled similarly to data-carrying variants in mixed enums.
When
Unit variants are mapped to keywords using their Rust identifier converted
via to_css_identifier. Attributes like #[css(keyword = "...")] are not
yet supported in this path (see bug 1995187).
For other kinds of types (e.g. unions), no to_typed method is generated;
the default implementation applies, which always returns None.
This allows keywords to be reified automatically into CSSKeywordValue
objects, while leaving more complex value types to be implemented
incrementally as Typed OM support expands.