askama-enum

Crates.ioaskama-enum
lib.rsaskama-enum
version0.0.2
sourcesrc
created_at2022-04-21 07:36:30.570599
updated_at2022-04-22 05:22:16.200356
descriptionImplement different askama templates for different enum variants
homepagehttps://github.com/Kijewski/askama-enum
repositoryhttps://github.com/Kijewski/askama-enum
max_upload_size
id571406
size43,624
(Kijewski-crates-graveyard)

documentation

README

askama-enum

GitHub Workflow Status Crates.io Minimum supported Rust version License

Implement different Askama templates for different enum variants.

#[derive(EnumTemplate)]
#[template(ext = "html", source = "default")] // default, optional
enum MyEnum<'a, T: std::fmt::Display> {
    // uses the default `#[template]`
    A,

    // uses specific `#[template]`
    #[template(ext = "html", source = "B")]
    B,

    // you can use tuple structs
    #[template(
        ext = "html",
        source = "{{self.0}} {{self.1}} {{self.2}} {{self.3}}",
    )]
    C(u8, &'a u16, u32, &'a u64),

    // and named fields, too
    #[template(ext = "html", source = "{{some}} {{fields}}")]
    D { some: T, fields: T },
}

assert_eq!(
    MyEnum::A::<&str>.to_string(),
    "default",
);
assert_eq!(
    MyEnum::B::<&str>.to_string(),
    "B",
);
assert_eq!(
    MyEnum::C::<&str>(1, &2, 3, &4).to_string(),
    "1 2 3 4",
);
assert_eq!(
    MyEnum::D { some: "some", fields: "fields" }.to_string(),
    "some fields",
);
Commit count: 4

cargo fmt