Skip to main content

ToTyped

Trait ToTyped 

Source
pub trait ToTyped {
    // Provided methods
    fn to_typed(&self, _dest: &mut ThinVec<TypedValue>) -> Result<(), ()> { ... }
    fn to_typed_value(&self) -> Option<TypedValue> { ... }
    fn to_typed_value_list(&self) -> Option<TypedValueList> { ... }
}
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.

Most consumers should use ToTyped::to_typed_value or ToTyped::to_typed_value_list, depending on whether they need a single reified value or the full list of reified values.

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: By default, the derive attempts to call .to_typed() recursively on supported fields or variant payloads, producing TypedValues when possible. This recursion can be disabled with #[typed(skip_derive_fields)].

  • Other cases: If no automatic mapping is defined, or recursion is explicitly disabled, the derived implementation falls back to the default method (which returns Err(()), and thus to_typed_value() returns None).

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

Summary of derive attributes recognized by #[derive(ToTyped)]:

  • #[typed(skip_derive_fields)] on the type disables recursion for structs and data-carrying enum variants.

  • #[css(skip)], #[typed(skip)], or #[typed(todo)] on a variant cause that variant to be treated as unsupported (the derived implementation returns Err(())).

  • #[css(skip)] on a field causes that field to be ignored during reification.

  • #[typed(skip_if = "...")] on a field conditionally disables reification for that field. If the provided function returns true for the field value, the field is ignored.

  • #[css(keyword = "...")] on a unit variant overrides the keyword that would otherwise be derived from the Rust identifier.

  • #[css(comma)] on the variant indicates that supported fields may reify to multiple separate values. When this attribute is present, multiple TypedValue items may be produced. If it is not present and the derived implementation would produce more than one item, it returns Err(()).

  • #[css(iterable)] on a field indicates that the field represents a list of values. Each item in the iterable is reified individually by calling ToTyped::to_typed on the element type.

  • #[css(if_empty = "...")] on an iterable field specifies a keyword value that should be produced when the iterable is empty.

Provided Methods§

Source

fn to_typed(&self, _dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Attempt to convert self into one or more TypedValue items.

Implementations append any resulting values to dest. This is the low-level entry point used by the Typed OM reification infrastructure. Most callers should prefer ToTyped::to_typed_value or ToTyped::to_typed_value_list.

Returning Err(()) indicates that the value cannot be represented as a property-agnostic Typed OM value.

Source

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

Attempt to convert self into a TypedValue.

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

Source

fn to_typed_value_list(&self) -> Option<TypedValueList>

Attempt to convert self into a TypedValueList.

Returns Some(TypedValueList) if the value can be reified into one or more property-agnostic Typed OM values. Returns None if the value is unrepresentable, in which case consumers produce a property-tied CSSStyleValue instead.

Implementations on Foreign Types§

Source§

impl ToTyped for Au

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Source§

impl<'a> ToTyped for f32

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Source§

impl<'a> ToTyped for i8

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Source§

impl<'a> ToTyped for i32

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Source§

impl<'a, T> ToTyped for &'a T
where T: ToTyped + ?Sized,

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Source§

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

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Source§

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

Source§

fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()>

Implementors§