Code Monkey home page Code Monkey logo

Comments (7)

lambda-fairy avatar lambda-fairy commented on May 20, 2024 1

Okay, that makes sense -- thanks. I have a feeling we need to go all the way to arbitrary Rust statements to solve your problem though. Maybe just a @let special form would be enough?

I'll need to think about this a bit more.

from maud.

TheNeikos avatar TheNeikos commented on May 20, 2024 1

I have to say that I didn't need to do this so far, anything that should be run once can be run outside the macro, and the @if let syntax allows for the rest

Note: I'm not trying to argue too hard against it, however it doesn't feel like something that is necessary.

from maud.

lambda-fairy avatar lambda-fairy commented on May 20, 2024 1

Implemented in 39602a0. The new @let form is pretty much like @if let, except the pattern cannot fail.

@Sackery I don't want to allow arbitrary Rust statements within a template. If your view logic is complicated enough that you need a whole block for it, then that's a sign that it should be in a separate function altogether.

from maud.

lambda-fairy avatar lambda-fairy commented on May 20, 2024

Can you give me an example of how such a feature would be used?

I've considered it in the past, but held back because I couldn't find a use case for it.

Note that you can declare variables outside the html! block as well.

from maud.

 avatar commented on May 20, 2024

because some situation e.g. @for n in 1..2 {}.
we want to insert normal rust expression to cache something.

from maud.

 avatar commented on May 20, 2024
@for n in somethings {
    div {
        @ { // here are any rust normal code.
            let item = n.something.unwrap(); // here item in something is move out, so we cannot unwrap twise.
        }
        h1 { (item.name) }
        a { (item.age) }
    }
}

from maud.

 avatar commented on May 20, 2024

but maybe this is powerful and smart.

html! {
    @ {
        somefunction(); // I can run any rust code here.
    }
}

from maud.

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.