Skip to main content

ThemeFields

Derive Macro ThemeFields 

Source
#[derive(ThemeFields)]
{
    // Attributes available to this derive:
    #[theme_layer]
}
Expand description

Derive macro that registers a plain struct’s serialized field names in the crate::resolve::FieldInfo inventory for TOML linting (Phase 93-05 G5).

By default the macro introspects the struct’s fields and honours any #[serde(rename = "...")] attributes (so corner_radius annotated with #[serde(rename = "corner_radius_px")] is registered under the wire name).

§Struct-level attributes

  • #[theme_layer(fields = "a, b_px, c")] – explicit field-name list. Use this for serde-proxy structs (like FontSpec, which serializes through a private FontSpecRaw proxy) where the user-facing struct’s field names do not match the wire format.

§Example

ⓘ
use native_theme_derive::ThemeFields;

// Introspection path: serde renames picked up automatically.
#[derive(ThemeFields, serde::Serialize, serde::Deserialize)]
pub struct Simple {
    pub a: i32,
    #[serde(rename = "bar")]
    pub b: i32,
}
// Registers { struct_name: "Simple", field_names: &["a", "bar"] }.

// Explicit-override path: used when serde proxy field names differ.
#[derive(ThemeFields, serde::Serialize, serde::Deserialize)]
#[serde(try_from = "HasProxyRaw", into = "HasProxyRaw")]
#[theme_layer(fields = "x, y_px, z")]
pub struct HasProxy { /* ... */ }

This derive emits ONLY an inventory::submit! call; it does not emit a FIELD_NAMES associated constant. To also get widget-style codegen (Resolved pair + merge + validate + FIELD_NAMES), combine with #[derive(ThemeWidget)].