maciejhirsz / ramhorns

Fast Mustache template engine implementation in pure Rust.
https://crates.io/crates/ramhorns
Mozilla Public License 2.0
293 stars 29 forks source link

Add derive attributes for renaming or skipping a field #30

Closed grego closed 4 years ago

grego commented 4 years ago

Sometimes it's desirable to use a field in a template with a different name, or for safety or other reasons to not allow using the field to render add all. This PR adds derive attributes in style of serde field attributes for skipping or renaming a field in a struct. The attributes can be used on fields as follows:

#[derive(Content)]
struct Data<'a> {
    #[ramhorns(skip)]
    secret: &'a str,
    #[ramhorns(rename = "new")]
    old: &'a str,
}
maciejhirsz commented 4 years ago

This is great! I'll release this with some other changes of mine later tonight.

maciejhirsz commented 4 years ago

@grego published this along with my parsing performance improvements as 0.9.2.