Skip to content

docs: fix recursive example in template_syntax.md #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

m4tx
Copy link
Contributor

@m4tx m4tx commented Jan 14, 2025

The original description mentions askama issues which is confusing, since they don't exist in rinja repo and, most importantly, the example doesn't compile at all. This fixes both issues.

Output

Tested with the following code:

use rinja::Template;

#[derive(Template)]
#[template(source = r#"
{{ name }} {
{% for item in children %}
   {{ item.render().unwrap() }}
{% endfor %}
}
"#, ext = "html", escape = "none")]
struct Item<'a> {
    name: &'a str,
    children: &'a [Item<'a>],
}

fn main() {
    let xd = Item {
        name: "test1",
        children: &[
            Item {
                name: "test2",
                children: &[
                    Item {
                        name: "test3",
                        children: &[]
                    }
                ]
            }
        ]
    };

    println!("{}", xd.render().unwrap());
}

Which prints:

test1 {

   
test2 {

   
test3 {

}


}


}

Old behavior

The old code fails to compile with:

error: reached the recursion limit while instantiating `filters::escape::_::<impl FastWritable for &Item<'_>>::write_into::<filters::escape::EscapeWriter<&mut filters::escape::EscapeWriter<..., ...>, ...>>`
   --> /home/m4tx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rinja-0.3.5/src/filters/escape.rs:511:17
    |
511 |                 <T>::write_into(self, dest)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: `filters::escape::_::<impl FastWritable for &T>::write_into` defined here
   --> /home/m4tx/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rinja-0.3.5/src/filters/escape.rs:510:13
    |
510 |             fn write_into<W: fmt::Write + ?Sized>(&self, dest: &mut W) -> fmt::Result {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: the full type name has been written to '/home/m4tx/projects/rust-test/target/debug/deps/rust_test-7872518c4b30a6ab.long-type.txt'

The original description mentions askama issues which is confusing, since they don't exist in rinja repo and, most importantly, the example doesn't compile at all. This fixes both issues.
Copy link
Member

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Kijewski Kijewski merged commit 5c6f61e into askama-rs:master Jan 14, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants