3 Declarations can be annotated with ‘attributes’ in Rust. They look like this:
18 The difference between the two is the `!`, which changes what the attribute
30 The `#[foo]` attribute applies to the next item, which is the `struct`
31 declaration. The `#![bar]` attribute applies to the item enclosing it, which is
32 the `mod` declaration. Otherwise, they’re the same. Both change the meaning of
33 the item they’re attached to somehow.
35 For example, consider a function like this:
44 It is marked with `#[test]`. This means it’s special: when you run
45 [tests][tests], this function will execute. When you compile as usual, it won’t
46 even be included. This function is now a test function.
50 Attributes may also have additional data:
58 Or even keys and values:
61 #[cfg(target_os = "macos")]
66 Rust attributes are used for a number of different things. There is a full list
67 of attributes [in the reference][reference]. Currently, you are not allowed to
68 create your own attributes, the Rust compiler defines them.
70 [reference]: ../reference.html#attributes