aro-macros 1.0.0

Procedural macros for the Aro web framework
Documentation
//! Procedural macros for the Aro web framework.
//!
//! Provides HTTP method attribute macros (`#[get("/path")]`, `#[post("/path")]`, etc.)
//! and the `AroEntity` derive macro for reducing per-entity boilerplate.

mod crate_path;
mod entity;
mod route;

use proc_macro::TokenStream;

/// Attach a `GET` route to a handler function.
///
/// # Example
///
/// ```ignore
/// #[get("/users/{id}")]
/// fn show_user(id: u64) { /* ... */ }
/// ```
#[proc_macro_attribute]
pub fn get(args: TokenStream, input: TokenStream) -> TokenStream {
    route::expand_route("get", args.into(), input.into()).into()
}

/// Attach a `POST` route to a handler function.
#[proc_macro_attribute]
pub fn post(args: TokenStream, input: TokenStream) -> TokenStream {
    route::expand_route("post", args.into(), input.into()).into()
}

/// Attach a `PUT` route to a handler function.
#[proc_macro_attribute]
pub fn put(args: TokenStream, input: TokenStream) -> TokenStream {
    route::expand_route("put", args.into(), input.into()).into()
}

/// Attach a `DELETE` route to a handler function.
#[proc_macro_attribute]
pub fn delete(args: TokenStream, input: TokenStream) -> TokenStream {
    route::expand_route("delete", args.into(), input.into()).into()
}

/// Attach a `PATCH` route to a handler function.
#[proc_macro_attribute]
pub fn patch(args: TokenStream, input: TokenStream) -> TokenStream {
    route::expand_route("patch", args.into(), input.into()).into()
}

/// Derive macro to generate Aro entity trait implementations.
///
/// Generates implementations of `aro_core::Entity`, `fletch_orm::Entity`, and
/// `sqlx::FromRow` from a single annotated domain struct.
///
/// # Struct Attributes
///
/// - `#[aro(table = "table_name")]`: Override the table name
///   (default: `snake_case` pluralized struct name).
///
/// # Field Attributes
///
/// - `#[aro(id)]` (required, exactly one): Marks the primary key field.
/// - `#[aro(skip)]`: Exclude a field from persistence. Skipped fields are
///   populated with `Default::default()` in the generated `FromRow` impl.
/// - `#[aro(rename = "col_name")]`: Override the column name.
///
/// # Example
///
/// ```ignore
/// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, AroEntity)]
/// #[aro(table = "users")]
/// pub struct User {
///     #[aro(id)]
///     pub id: i64,
///     pub name: String,
///     pub email: String,
/// }
/// ```
#[proc_macro_derive(AroEntity, attributes(aro))]
pub fn derive_aro_entity(input: TokenStream) -> TokenStream {
    entity::expand_aro_entity(input.into()).into()
}