Attributes and Derive in Rust
An attribute is a note attached to a piece of code that tells the compiler to treat it specially, and derive is the attribute that asks the compiler to write a standard implementation for you. They are how you turn on a feature, silence a warning, or get common behaviour without typing it out. In kernel code, attributes are also how macros mark the structures they are about to rewrite.
Questions this Concept answers
- Why does kernel Rust mark a structure shared with C as `#[repr(C)]` instead of leaving the default layout?
Attributes - Rust By Example
An attribute is a note you attach to Rust code that tells the compiler to treat that code specially. This page shows the two forms: #[...] applies to the item right below it, such as a function or st…