ToTyped

Trait ToTyped 

Source
pub trait ToTyped {
    // Provided method
    fn to_typed(&self) -> Option<TypedValue> { ... }
}
Expand description

Reifies a value into its Typed OM representation.

This trait is the Typed OM analogue of ToCss. Instead of serializing values into CSS syntax, it converts them into TypedValues that can be exposed to the DOM as CSSStyleValue subclasses.

This trait is derivable with #[derive(ToTyped)]. The derived implementation currently supports:

  • Keyword enums: Enums whose variants are all unit variants are automatically reified as TypedValue::Keyword, using the same serialization logic as ToCss.

  • Structs and data-carrying variants: When the #[typed_value(derive_fields)] attribute is present, the derive attempts to call .to_typed() recursively on inner fields or variant payloads, producing a nested TypedValue representation when possible.

  • Other cases: If no automatic mapping is defined or recursion is not enabled, the derived implementation falls back to the default method, returning None.

The derive_fields attribute is intentionally opt-in for now to avoid forcing types that do not participate in reification to implement ToTyped. Once Typed OM coverage stabilizes, this behavior is expected to become the default (see the corresponding follow-up bug).

Over time, the derive may be extended to handle additional CSS value categories such as numeric, color, and transform types.

Provided Methods§

Source

fn to_typed(&self) -> Option<TypedValue>

Attempt to convert self into a TypedValue.

Returns Some(TypedValue) if the value can be reified into a property-agnostic CSSStyleValue subclass. Returns None if the value is unrepresentable, in which case reification produces a property-tied CSSStyleValue instead.

Implementations on Foreign Types§

Source§

impl ToTyped for Au

Source§

impl<'a> ToTyped for f32

Source§

impl<'a> ToTyped for i8

Source§

impl<'a> ToTyped for i32

Source§

impl<T> ToTyped for Box<T>
where T: ?Sized + ToTyped,

Implementors§