Open jaw-sh opened 6 months ago
I don't like this. It would be super cool if there was a way to simply
{{ result }}
and render either branch automatically.
Have a look how to implement custom filters. Adding your own |either_result
filter would be simple enough.
I wouldn't like askama to branch both cases automagically, because I would most like wrap the error message in e.g. <div class="error">
. If the template engine makes it harder to find such cases, it would be a disadvantage to me.
Have a look how to implement custom filters. Adding your own
|either_result
filter would be simple enough.
I did attempt this but had compiler errors regarding sized types and another anomalous issues I couldn't resolve myself. I would accept this as a solution if I could manage it.
Have a look how to implement custom filters. Adding your own
|either_result
filter would be simple enough.I did attempt this but had compiler errors regarding sized types and another anomalous issues I couldn't resolve myself. I would accept this as a solution if I could manage it.
A filter should definitely be possible. Do you have the exact error message?
I don't think there's a general solution here because a blanket impl for Display
for Result<T, E>
just doesn't make sense even if T
and E
both implement Display
. A Display
impl might be possible (coherence willing) for specific T
/E
combinations, of course.
A filter or macro definitely feels like the straightforward option here.
I have a template that I call a View. It has implementations which return templates-in-templates with derived values. Sometimes these can fail and return results. These results need to be handled inside the template, even though both arms of Result<> implement Display.
My template could look like this:
Instead, it must look like this:
I don't like this. It would be super cool if there was a way to simply
{{ result }}
and render either branch automatically.