Comments (12)
Should be straightforward. I only handle the lifetimes
part of Generics
so far because I was lazy/test-driven.
from askama.
Nice. I think as long as you detect this case and fail with a better message, this can wait until after you announce the project.
from askama.
Nah, might as well fix it now. Shouldn't be too hard to at least fix the simple cases.
from askama.
BTW, I think your test as written will not work. There needs to be a trait bound T: std::fmt::Display
added, but I assume that would be acceptable. I have a fix for this which I'll try to push tonight.
from askama.
Askama should infer the bound, similar to what we do in Serde. This works:
#[derive(Serialize, Deserialize)]
struct Test<T> {
t: T,
}
from askama.
How does that work in Serde? I'm not sure it would work in Askama, or at least it seems like it would make Askama an order of magnitude more complex than it currently is. This is because Askama templates can require arbitrary complexity from types of fields in the template (which I think is quite a bit different from Serde).
from askama.
(That is to say, it would be fairly easy for this specific case, but it seems Hard for the general case.)
from askama.
You're right, I did not consider that arbitrary expressions make it not feasible to infer bounds.
Either of these should work when using {{ t }}
, right?
#[derive(Template)]
#[template(path = "test")]
struct Test<T: Display> {
t: T,
}
#[derive(Template)]
#[template(path = "test")]
struct Test<T> where T: Display {
t: T,
}
from askama.
Yup, I have that covered.
from askama.
BTW, I was using to_tokens()
to copy over the trait bounds and noticed that the spacing doesn't look so nice, is that worth a bug? I can understand if it's too hard to fix generically in syn or quote.
from askama.
to_tokens()
is not designed to generate human-readable output. It is for handing tokens to the compiler. If the user wants to see the generated code they can run cargo expand
and see pretty formatted output. Syn / quote should not need to re-implement a pretty-printer for that.
from askama.
(Added test case in f71b2f0, which I tagged with the wrong issue number by mistake.)
from askama.
Related Issues (20)
- Allowing imports and macro declaration everywhere? HOT 2
- I could not give relative path to template on linux but can give on windows HOT 7
- Issue
- Regression in askama_parser 0.2.0 update HOT 14
- Composing templates HOT 3
- 8e03fa6132669383a763d628b7443d1758b50400 HOT 1
- Document the `fmt` filter HOT 3
- Can't render simple template. Axum integration. HOT 2
- Add support for filter section HOT 5
- Document how integration should be imported HOT 1
- Remove the need to import askama itself when using integration crates HOT 3
- Why if block does not work inside another block HOT 4
- Rust macro has no access to parameters passed into `{% macro f(param) %}` HOT 6
- div appear with its classes initially in case of an Option HOT 3
- Ignore templates in HTML comments to sidestep `no field ... exists` and other errors when design iterating HOT 3
- Conditional HTML attributes HOT 4
- Unify integration API HOT 1
- Allow support for control blocks in (named) arguments? HOT 3
- Scope changes inside `block`, preventing to call macros which should be in scope HOT 7
- dynamic rendering based on html HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from askama.