Attributes
Attributes are a core part of Pavex's design. You'll use attributes to define every single Pavex component, from routes to middlewares:
use pavex::Response;
use pavex::get;
#[get(path = "/")] // (1)!
pub fn landing_page() -> Response {
// [...]
}
- The
#[pavex::get]attribute is used to define a new route for the landing page.
We will refer to an item with a Pavex attribute as an annotated item.
The API reference has an exhaustive list of all required and optional arguments for each attribute1. Nonetheless, a few mechanisms are common to all attributes:
- Generation (and customization) of component ids
- Syntax to annotate functions and methods
- Syntax to annotate types
This guide focuses on these cross-cutting concerns.
-
Check out the reference for
#[pavex::get]as an example of the documentation format. ↩