ferro-macros

Crates.ioferro-macros
lib.rsferro-macros
version0.1.71
created_at2026-01-16 17:12:46.31075+00
updated_at2026-01-17 20:04:16.197738+00
descriptionProcedural macros for Ferro framework
homepage
repositoryhttps://github.com/albertogferrario/ferro
max_upload_size
id2048977
size102,531
Alberto Giancarlo Ferrario (albertogferrario)

documentation

README

ferro-macros

Procedural macros for the Ferro framework.

Macros

#[handler]

Transform functions into HTTP handlers with automatic parameter extraction:

use ferro::{handler, Request, Response};

#[handler]
pub async fn show(req: Request, id: i64) -> Response {
    // id is extracted from path parameter
    Ok(json!({"id": id}))
}

#[request]

Define validated request data:

use ferro::request;

#[request]
pub struct CreateUserRequest {
    #[validate(email)]
    pub email: String,

    #[validate(length(min = 8))]
    pub password: String,
}

#[service]

Mark traits for dependency injection:

use ferro::service;

#[service]
pub trait UserService: Send + Sync {
    async fn find(&self, id: i64) -> Option<User>;
}

#[injectable]

Auto-register implementations as singletons:

use ferro::injectable;

#[injectable]
pub struct AppState {
    pub counter: u32,
}

#[domain_error]

Define domain errors with HTTP response conversion:

use ferro::domain_error;

#[domain_error(status = 404, message = "User not found")]
pub struct UserNotFoundError {
    pub user_id: i64,
}

inertia_response!

Create Inertia.js responses with compile-time component validation:

use ferro::inertia_response;

inertia_response!("Users/Index", UsersProps { users })

describe! and test!

Jest-like testing macros:

use ferro::{describe, test, expect};

describe!("UserService", {
    test!("finds user by id", async fn(db: TestDatabase) {
        let user = UserService::find(1).await;
        expect!(user).to_be_some();
    });
});

License

MIT

Commit count: 515

cargo fmt