oxide_framework_macros/lib.rs
1use proc_macro::TokenStream;
2
3mod controller;
4
5/// Marks an `impl` block as an Oxide controller.
6///
7/// Generates a [`Controller`] trait implementation that registers all
8/// route-annotated methods under the given URL prefix.
9///
10/// # Example
11///
12/// ```rust,ignore
13/// #[controller("/api/users")]
14/// impl UserController {
15/// fn new(state: &AppState) -> Self { /* ... */ }
16///
17/// #[get("/")]
18/// async fn list(&self) -> ApiResponse<Vec<User>> { /* ... */ }
19///
20/// #[get("/{id}")]
21/// async fn get_one(&self, Path(id): Path<u64>) -> ApiResponse<User> { /* ... */ }
22/// }
23/// ```
24#[proc_macro_attribute]
25pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
26 controller::expand(attr.into(), item.into())
27 .unwrap_or_else(|err| err.to_compile_error())
28 .into()
29}
30