In this ↓ example we have a tree-like structure where Person contains children: &[Person]:
#[derive(Template)]
#[template(
ext = "html",
source = "{{name}}<{% for child in children %}{{ child }},{% endfor %}>"
)]
struct Person<'a> {
name: &'a str,
children: &'a [Person<'a>],
}
This example will fail to compile, because in here child is rendered with escaping. Because of that the Writer template argument be will become unrestrictedly large: EscapeWriter<EscapeWriter<EscapeWriter< … >>>. With each recursion the Writer gets one more nesting level. The recursion depth is unlimited, so no such writer can be constructed.
The problem can be resolved by adding |safe, so the no escaper is used. Using the Text escaper (ext = "txt") does not work, because even though it does not transform the input, it still winds up as template argument. I don't think that we can catch the problem to give the user a better error message.
The Writer is std::fmt::Writer, which is dyn-compatible. It might be possible break the recursion by adding an alternative escape filter that does not accept a generic impl fmt::Writer, but a dyn fmt::Writer.
In this ↓ example we have a tree-like structure where
Personcontainschildren: &[Person]:This example will fail to compile, because in here
childis rendered with escaping. Because of that theWritertemplate argument be will become unrestrictedly large:EscapeWriter<EscapeWriter<EscapeWriter< … >>>. With each recursion theWritergets one more nesting level. The recursion depth is unlimited, so no such writer can be constructed.The problem can be resolved by adding
|safe, so the no escaper is used. Using theTextescaper (ext = "txt") does not work, because even though it does not transform the input, it still winds up as template argument. I don't think that we can catch the problem to give the user a better error message.The
Writerisstd::fmt::Writer, which is dyn-compatible. It might be possible break the recursion by adding an alternative escape filter that does not accept a genericimpl fmt::Writer, but adyn fmt::Writer.