Expand description
Auto-route registration using linkme distributed slices
This module enables zero-config route registration. Routes decorated with
#[rustapi::get], #[rustapi::post], etc. are automatically collected at link-time.
§How It Works
When you use #[rustapi::get("/path")] or similar macros, they generate a
static registration that adds the route factory function to a distributed slice.
At runtime, RustApi::auto() collects all these routes and registers them.
§Example
ⓘ
use rustapi_rs::prelude::*;
#[rustapi::get("/users")]
async fn list_users() -> Json<Vec<User>> {
Json(vec![])
}
#[rustapi::post("/users")]
async fn create_user(Json(body): Json<CreateUser>) -> Created<User> {
// ...
}
#[rustapi::main]
async fn main() -> Result<()> {
// Routes are auto-registered, no need for manual .mount() calls!
RustApi::auto()
.run("0.0.0.0:8080")
.await
}Statics§
- AUTO_
ROUTES - Distributed slice containing all auto-registered route factory functions.
Functions§
- auto_
route_ count - Get the count of auto-registered routes without collecting them.
- collect_
auto_ routes - Collect all auto-registered routes.