“I think proc macros are a really big superpower for Rust.”
Yeah, been working on a framework and proc-macros are really useful to simplify the API.
For example, previously I needed users to define a struct and then an impl block with a function inside. Well, and they need to do that a lot, so it was genuinely a bit of a pain to write out, but it also made the code feel more complex than it really was.
Now I’ve got an annotation, which you can slap onto a function and then it generates the struct from the function parameters and puts the function into the impl block.
And while you do need to be aware that the function parameters will be put into a struct and therefore you want owned parameters, all-in-all it still feels really nice to just delete dozens of boilerplate lines and an indentation level in the codebases where I’ve introduced it.
Yeah, been working on a framework and proc-macros are really useful to simplify the API.
For example, previously I needed users to define a struct and then an
implblock with a function inside. Well, and they need to do that a lot, so it was genuinely a bit of a pain to write out, but it also made the code feel more complex than it really was.Now I’ve got an annotation, which you can slap onto a function and then it generates the struct from the function parameters and puts the function into the
implblock.And while you do need to be aware that the function parameters will be put into a struct and therefore you want owned parameters, all-in-all it still feels really nice to just delete dozens of boilerplate lines and an indentation level in the codebases where I’ve introduced it.