magic-params

Crates.iomagic-params
lib.rsmagic-params
version0.0.4
created_at2025-08-31 19:58:22.839537+00
updated_at2025-08-31 23:14:32.898094+00
descriptionMacro to call functions with typed arguments derived from a shared context.
homepage
repositoryhttps://github.com/xiao-e-yun/MagicParams
max_upload_size
id1818858
size6,684
小惡運 (xiao-e-yun)

documentation

README

Magic Params

call functions with typed arguments derived from a shared context.

Reference: axum-style-magic-function-param

Usage

cargo add magic-params

Examples

define_context!(MyContext {
    value1: i32,
    value2: u32,
    value3: String,
});
context_as_params!(MyContext, 3);

fn main() {
    let ctx = MyContext {
        value1: 42,
        value2: 100,
        value3: "Hello".to_string(),
    };

    let handler = |v1: i32, v2: u32, v3: String| {
        assert_eq!(v1, 42);
        assert_eq!(v2, 100);
        assert_eq!(v3, "Hello");
        "Handler called successfully"
    };

    assert_eq!(handler.call(&ctx), "Handler called successfully");
}
Commit count: 5

cargo fmt