| Crates.io | magic-params |
| lib.rs | magic-params |
| version | 0.0.4 |
| created_at | 2025-08-31 19:58:22.839537+00 |
| updated_at | 2025-08-31 23:14:32.898094+00 |
| description | Macro to call functions with typed arguments derived from a shared context. |
| homepage | |
| repository | https://github.com/xiao-e-yun/MagicParams |
| max_upload_size | |
| id | 1818858 |
| size | 6,684 |
call functions with typed arguments derived from a shared context.
Reference: axum-style-magic-function-param
cargo add magic-params
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");
}