4 ms·
Doesn’t Rust have “comments working like syntax” in the form of #[derive] etc.? I’ve only read through the rust book without using it for anything (yet) and ha
by corytheboyd 6y ago
Doesn’t Rust have “comments working like syntax” in the form of #[derive] etc.?
I’ve only read through the rust book without using it for anything (yet) and have done no work on golang, so I’m legitimately curious to hear your input, not challenging you on semantics :p
Edit: Rust does not use # for comments. Sorry I just had that mixed up in my head, but thanks for the answers!
- brundolf 6y ago#[...] is an attribute, more like @foo annotations in Java, not a comment. Comments do not use # in Rust
- corytheboyd 6y ago> Comments do not use # in Rust Oof what a dumb mistake, sorry about that!
- felipellrocha 6y agoIt's ok. Other people probably had the same question!
- cesarb 6y agoThese #[...] and #![...] are not comments; they're attributes (somewhat similar to Java's @Something annotations). Comments in Rust start with // or /<star> like in C or C++. There's only the special case that "doc comments" (starting with /// or /<star><star> or //! or /<star>!) are automatically converted into #[doc="..."] or #![doc="..."] attributes. The difference is that attributes are always meaningful to the compiler (and can only be used in specific places); other than doc comments (which turn into attributes), comments never are meaningful to the compiler. (edit: HN's comment markup eats the * character, I replaced them with <star> above)