News for hackers. Stuff that matters.
Re:Maud: A Rust macro for writing HTML by IshKebab on Tuesday June 07, 2022 @02:58AM (#31650735)
The main problem with macros like this (aside from being yet another language to learn) is that they don't work nicely with IDEs.
Re:Maud: A Rust macro for writing HTML by czei002 on Tuesday June 07, 2022 @03:30AM (#31650935)
Totally agree, macros are the worst Rust feature for me, they are way too powerful and break the tooling, e.g. fmt or language server.

https://rust-analyzer.github.io/blog/2021/11/21/ides-and-mac...

Re:Maud: A Rust macro for writing HTML by pizza234 on Tuesday June 07, 2022 @04:06AM (#31651183)
It ultimately depends on how they're written. println! is a macro, and doesn't "break the tooling". on the other end of the spectrum, using a crate like demonstrate (unit testing) produces hard to understand errors and slows down the IDE.

I don't remember experiencing Rust Analyzer crashes for a long time, though (I do remember some in the past).

Re:Maud: A Rust macro for writing HTML by shepmaster on Tuesday June 07, 2022 @09:09AM (#31653705)
> println! is a macro, and doesn't "break the tooling"

I like, use, and write macros, but this isn't fully true. For example, recent Rust versions allow writing identifiers directly in the format string:

    println!("{some_identifier}")
However, this breaks rust-analyzer's ability to rename variables [1].

[1]: https://github.com/rust-lang/rust-analyzer/issues/11260#

Re:Maud: A Rust macro for writing HTML by tialaramex on Tuesday June 07, 2022 @06:22AM (#31652116)
println! is only a declarative macro, whereas Maud is a proc macro.

The declarative macros aren't too head-twisting for tools, they just expand as declared, this can sometimes have a few surprising effects but generally it is very manageable. Procedural macros have essentially unlimited power and thus are sometimes entirely impossible to analyse.

Re:Maud: A Rust macro for writing HTML by pornel on Tuesday June 07, 2022 @07:45AM (#31652736)
Re:Maud: A Rust macro for writing HTML by tialaramex on Wednesday June 08, 2022 @03:41AM (#31664455)
I see a built-in there. Are you really seeing a proc macro?
Re:Maud: A Rust macro for writing HTML by dustymcp on Tuesday June 07, 2022 @03:04AM (#31650774)
Isnt it just easier to have a html file then replace tags inside of that rather than having a new macro language ?
Re:Maud: A Rust macro for writing HTML by tannhaeuser on Tuesday June 07, 2022 @04:13AM (#31651230)
SGML (the markup meta-language once used for describing HTML) has that, but as we're talking the verdict is still out whether that's actually easier [1] ;) But anyway, SGML gives you HTML-aware, context-dependent, injection-free templating (even with hard support for sanitizing user content) in a content authoring workflow independent from a hosting programming language so is in a different ball park.

[1]: https://news.ycombinator.com/item?id=31637910

Re:Maud: A Rust macro for writing HTML by josephg on Tuesday June 07, 2022 @03:10AM (#31650814)
This also supports conditional expressions and loops:

https://maud.lambda.xyz/control-structures.html

Re:Maud: A Rust macro for writing HTML by fredrb on Tuesday June 07, 2022 @03:29AM (#31650926)
So does most templating languages.
Re:Maud: A Rust macro for writing HTML by coffeeblack on Tuesday June 07, 2022 @03:26AM (#31650913)
Shouldn’t it work in any IDE that understands Rust macros?
Re:Maud: A Rust macro for writing HTML by tialaramex on Tuesday June 07, 2022 @03:55AM (#31651108)
You can't build an IDE that definitely just "understands Rust macros" since procedural macros in particular are in effect modifying your compiler. Maud is a proc macro.

Mara's whichever_compiles! macro for example: https://github.com/m-ou-se/whichever-compiles -- that macro is forking your compiler to try out all the branches and throwing away branches which caused a compile error.

Clearly your IDE should throw its hands up and say, I don't understand what this does, I give up.

In general doing something useful with Rust macros is a more tractable problem for an IDE than say the C pre-processor, because Rust's macros have a stronger syntax, but the proc macro is potentially much too powerful / dangerous to try to evaluate.

Re:Maud: A Rust macro for writing HTML by msk-lywenn on Tuesday June 07, 2022 @03:51AM (#31651084)
Is there any? I don't think there is a real meaning to "understanding rust macros", as they define something completely new.
Re:Maud: A Rust macro for writing HTML by yakubin on Tuesday June 07, 2022 @06:51AM (#31652307)
They also slow down compilation.