Add support for macro args type annotations#722
Add support for macro args type annotations#722GuillaumeGomez merged 2 commits intoaskama-rs:mainfrom
Conversation
18e1970 to
653e423
Compare
|
Awesome, thank you for working on this! I just tried the following: use askama::Template;
struct ComplexStruct {
title: String,
icon: String,
}
#[derive(Template)]
#[template(
source = r#"
{%- macro test(entries: &[ComplexStruct]) -%}{% endmacro -%}
{{ test(&entries) }}
"#,
ext = "txt"
)]
struct Page {
entries: Vec<ComplexStruct>,
}
fn main() {
let page = Page {
entries: vec![ComplexStruct {
title: "title".to_string(),
icon: "icon".to_string(),
}],
};
page.render().unwrap();
}But am getting this error: |
653e423 to
bd6bf17
Compare
|
Updated with new tests (including yours). Can you give it another try please? |
|
Looks good! |
| source = r#" | ||
| {%- macro test(title: Option<u32> = None) -%}{% endmacro -%} | ||
| {%- let y = 12 -%} | ||
| {% call test(y) %}{% endcall -%} |
There was a problem hiding this comment.
It might make sense to also test the short call syntax in the tests:
{{ test(y) }}
There was a problem hiding this comment.
Adding a test for it.
Sadly it comes from the current limitations of the proc-macros error reporting. If we don't add a reference, it will then take ownership, leading to hard to track errors. So for now, it's simply a better user experience. Hopefully, once the proc-macro |
bd6bf17 to
724f05b
Compare
|
@seijikun Added the test you suggested, thanks for that! Also realized I forgot to add docs for it so added it as well. Seems like PR is ready to go. Merging once CI is happy. |
Fixes #514.
Does it look good to you @seijikun ?