← Back to context

Comment by Thaxll

2 days ago

`<button @click=$(|_e| count.increment())>"increment"</button>`

What the heck is this.

This is pretty easy to understand if you have a cursory understanding of Rust and HTML.

I won't get into the HTML part (I think it's obvious), but the

  $(|_e| count.increment())

part is a rust closure. |_e| is the argument to the closure, which has a leading underscore because it's unused. I imagine it's some context about the event (thus the e). The rest is the body of the closure. It increments the count.

pretty simply

  • GP is pointing out this introduces this kind of special DSL syntax with HTML tags into a procedural/functional language like rust?

    Even though macros can do this, it's not intuitive to expect this kind of JSX soup in rust. It's difficult to reason about than a function call. Something like flutter where widgets are ordinary function calls is far better.

    Plus the macros add to the compile time tax.

    This is another exhibit that rust is full of web programmers from React JS world (the above is exactly like JSX), all about aesthetics than practicality and predictability these days, pulling what should be a system language into incompatible directions.

    Long live zig for trying engineering directions rust couldn't. But we need a rust killer with memory safety which gatekeeps web programmers and slop peddlers.