Code Monkey home page Code Monkey logo

Comments (12)

djc avatar djc commented on July 21, 2024

Should be straightforward. I only handle the lifetimes part of Generics so far because I was lazy/test-driven.

from askama.

dtolnay avatar dtolnay commented on July 21, 2024

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.

djc avatar djc commented on July 21, 2024

Nah, might as well fix it now. Shouldn't be too hard to at least fix the simple cases.

from askama.

djc avatar djc commented on July 21, 2024

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.

dtolnay avatar dtolnay commented on July 21, 2024

Askama should infer the bound, similar to what we do in Serde. This works:

#[derive(Serialize, Deserialize)]
struct Test<T> {
    t: T,
}

from askama.

djc avatar djc commented on July 21, 2024

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.

djc avatar djc commented on July 21, 2024

(That is to say, it would be fairly easy for this specific case, but it seems Hard for the general case.)

from askama.

dtolnay avatar dtolnay commented on July 21, 2024

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.

djc avatar djc commented on July 21, 2024

Yup, I have that covered.

from askama.

djc avatar djc commented on July 21, 2024

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.

dtolnay avatar dtolnay commented on July 21, 2024

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.

djc avatar djc commented on July 21, 2024

(Added test case in f71b2f0, which I tagged with the wrong issue number by mistake.)

from askama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.