Skip to main content

ToCodeLiteral

Derive Macro ToCodeLiteral 

Source
#[derive(ToCodeLiteral)]
Expand description

Derive ToCodeLiteral for structs and enums.

Generates a #[cfg(feature = "emit")]-gated implementation that converts each field/variant into a TokenStream expression reconstructing the value.

§Structs

#[derive(ToCodeLiteral)]
struct ColorJson { r: f32, g: f32, b: f32, a: f32 }

§Enums

Handles unit, tuple, and struct variants:

#[derive(ToCodeLiteral)]
enum Align { Min, Center, Max }

Recursive types work automatically via existing Vec<T> / Option<T> blanket impls.