4 ms·
As mentioned, these are attributes not comments. More specifically, the the `#[derive]` attribute on the enum lists which procedural macros to execute (Debug an
by Measter 5y ago
As mentioned, these are attributes not comments. More specifically, the the `#[derive]` attribute on the enum lists which procedural macros to execute (Debug and Snafu here).
These procedural macros are handed the token stream for that enum, and can use that to generate new code. The Snafu macro here is also using attributes on each variant of the enum for information about how to implement certain things.
The documentation for Snafu has a page[1] describing what code is generated. There's nothing there that couldn't be done by hand, it's just tedious.
[1] https://docs.rs/snafu/0.6.10/snafu/guide/the_macro/index.html https://docs.rs/snafu/0.6.10/snafu/guide/the_macro/index.htm...
- dmix 5y ago> More specifically, the the `#[derive]` attribute on the enum lists which procedural macros to execute (Debug and Snafu here). Yep I've used Rust before... It's still like putting comments above your functions.
- kalcode 5y ago> It's still like putting comments above your functions. If you're used to a certain language then sure that makes sense. Your comment seems like you are boxing yourself in, limiting yourself to just what makes sense in Javascript, very opposite of a programmer who looks to improve their craft. Take a moment and think about that. Because it looks like Javascript comment...you only see it like that to a point of making this statement. There is a lot of ways different languages uses tokens/symbols to indicate something. Not everyone agrees what those symbols are used for. Some languages use it to define macros like C++ or preprocessor directives like C#. Some as comments JS/Python/. Some as like Java nothing. Because the languages you use are use to it, and the language you use doesn't use something similar, it looks "wrong". That is in itself a narrow view. I think you should question that kind of thinking, I believe it will be helpful.