handybars_macros 0.2.0

Attribute macro for annotating structs and enums as Handybars values
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 7.68 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 281.96 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 0x00002a

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.