handybars_macros

Crates.iohandybars_macros
lib.rshandybars_macros
version0.2.0
created_at2025-01-04 01:13:55.716044+00
updated_at2025-01-04 01:13:55.716044+00
descriptionAttribute macro for annotating structs and enums as Handybars values
homepage
repository
max_upload_size
id1503476
size7,044
Natasha England-Elbro (0x00002a)

documentation

README

Overview

This is an attribute macro that implements the Into<Value> trait for annotated structs and enums to be used with Handybars. Please refer to the main Handybars crate for information on how to use!

Implementation Notes

Annotating an enum or a struct with #[handybars_value] generates Into<Value> implementations for the item. For example, the #[handybars_value] attribute on the enum:

#[handybars_value]
enum SimpleEnumProp {
    A,
    B,
}

... will result in the following code being generated for the SimpleEnumProp:

impl<'v> Into<handybars::Value<'v>> for SimpleEnumProp {
    fn into(self) -> handybars::Value<'v> {
        match self {
            SimpleEnumProp::A => handybars::Value::String(std::borrow::Cow::from("A")),
            SimpleEnumProp::B => handybars::Value::String(std::borrow::Cow::from("B")),
        }
    }
}

Why use an attribute and not a derive process macro?

Derive Macros do not support implementing traits with generic arguments. In this case we need to implement Into<Value> for the annotated enum or struct. If Value had been a trait and not an enum, a derive macro would have been appropriate.

Commit count: 0

cargo fmt