| Crates.io | handybars_macros |
| lib.rs | handybars_macros |
| version | 0.2.0 |
| created_at | 2025-01-04 01:13:55.716044+00 |
| updated_at | 2025-01-04 01:13:55.716044+00 |
| description | Attribute macro for annotating structs and enums as Handybars values |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1503476 |
| size | 7,044 |
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!
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")),
}
}
}
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.