Are macros unreadable just for me?

Yes, pretty much. The difference is that our proc-macros are a mess, with no stable API, forcing everyone to become a synner.

1 Like

It's actually a Rust-Analyzer feature, not a VSCode feature.

1 Like

I know; VSCode is just an editor with plugins. But @Esperantisto implied he was using it, and while VSCode is using rust-analyzer, RustRover doesn't. Hence my comment: if one finds it too limited, they might want to try something else. I'm not sure it'll make a huge difference when it comes to tracing through macros, though.

I'm not sure you replied this, actually.

it's not, and that's ok :heart:

look, rust is great. but it has its limitations, and sometimes overly verbose syntax is one of those limitations. sometimes you want a bit less type safety than rust forces with functions. sometimes you can convert a long, multi-line span of boilerplate into one rust macro in a way that regular functions cant. sometimes it makes sense to just outright define a new syntax embedded in rust. thus, macros

i am a strong advocate for and user of rust macros. if you cant understand macros right now, you just need to put that on the list of things to learn. macros are an extremely flexible, compact way to remove boilerplate from a codebase. you just need to know how to use them. i really encourage you to take some time to write macros yourself; it's likely you'll start to see the utility as you go along

it's also worth mentioning that macros, at least the kind like rust's, are kinda a functional programming thing (think lisp). i mean, we have to acknowledge that rust is a functional programming language, and although there was some disparity put on haskell in this thread, rust is an ml based language which shares a lot of commonalities with haskell. for those of us who use rust as a highly performant functional language (unlike rust's garbage collected cousins in the ml family), macros are a relatively simple way to write highly abstract code at zero cost. macros cause no indirection and don't waste time on stack frame allocs, yet they allow you to write highly abstact, compact, functional code. a lot of people are scared of this kind of code, but you can thank these kinds of tools for rust's performance despite its level of abstraction

4 Likes

I have to say. The most worst-hit area is GUI lib. each lib use macro to insert their self DSL in code, and do not provide LSP or editor extension and format cli.
In contrast, the attribute macro in web framework is too user-friendly

1 Like

Macros are pretty readable in Nim as well, being written in more or less the same syntax as the language itself.

There some dedicated resources, e.g. this one

It's 10 years old, but I think still valid...

it's basically just a wrapper about predicate required for when the predicate is user must be logged in. they should have probably linked that in the docs

here is what it does

/// Predicate middleware.
///
/// Can be specified with a login URL and next redirect field or an alternative
/// which implements [`IntoResponse`](axum::response::IntoResponse).
///
/// When the predicate passes, the request processes normally. On failure,
/// either a redirect to the specified login URL is issued or the alternative is
/// used as the response.