News for hackers. Stuff that matters.
Re:Rust: A Critical Retrospective by TheSoftwareGuy on Thursday May 19, 2022 @02:34PM (#31438369)
Rust has an extremely powerful macro system, have you tried that?
Re:Rust: A Critical Retrospective by alpaca128 on Thursday May 19, 2022 @03:13PM (#31438823)
Rust macros are one of the more annoying features to me. They're great at first glance but whenever I want to build more fancy ones I constantly bump into limitations. For example they seem to be parsed without any lookahead, making it difficult to push beyond the typical function call syntax without getting compiler errors due to ambiguity.
Re:Rust: A Critical Retrospective by inferiorhuman on Thursday May 19, 2022 @04:10PM (#31439564)
Procedural macros have a peek function from the syn crate. macro_rules macros can stuff this into the pattern matching.

e.g.

https://turreta.com/2019/12/24/pattern-matching-declarative-...

Re:Rust: A Critical Retrospective by colejohnson66 on Friday May 20, 2022 @06:02PM (#31453070)
But proc macros are limited by requiring another crate (unless things have changed in the last year). Sure, it’s just one extra crate in the project, but why must I be forced to?
Re:Rust: A Critical Retrospective by inferiorhuman on Saturday May 21, 2022 @04:23AM (#31456217)
Asked and answered in an adjacent comment.
Re:Rust: A Critical Retrospective by xigoi on Friday May 20, 2022 @06:05AM (#31445368)
But there's the weird limitation that procedural macros have to be in a separate crate.
Re:Rust: A Critical Retrospective by efaref on Friday May 20, 2022 @06:39AM (#31445561)
Why is that weird? Procedural macros are compiler plugins. They get compiled for the platform you're building on, not the one you're building for, and so they need to be a separate compilation unit. In Rust, the crate is the compilation unit.
Re:Rust: A Critical Retrospective by xigoi on Friday May 20, 2022 @06:42AM (#31445576)
Because you can't just throw together a simple procedural macro to use in a specific project, as you can in other languages.