Attribrutes

  • An attribute is metadata applied to some module, crate or item
#[attribute = "value"]
#[attribute(key = "value")]
#[attribute(value)]
fn foo() {}
  • This metadata can be used to/for

    • conditional compilation of code
    • set crate name, version and type (binary or library)
    • disable lints (warnings)
    • enable compiler features (macros, glob imports, etc.)
    • link to a foreign library
    • mark functions as unit tests
    • mark functions that will be part of a benchmark
    • create custom decorator