Conceptual
Login

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?