| Crates.io | cli_hooks |
| lib.rs | cli_hooks |
| version | 0.1.0 |
| created_at | 2025-01-03 21:19:19.237036+00 |
| updated_at | 2025-01-03 21:19:19.237036+00 |
| description | A procedural macro that enables dynamic execution of Rust code before and after function calls. |
| homepage | https://github.com/MCarlomagno/cli-hooks-rs |
| repository | https://github.com/MCarlomagno/cli-hooks-rs |
| max_upload_size | |
| id | 1502864 |
| size | 33,694 |
⚠️ Warning: This project is experimental and under active development. The API and functionality may undergo significant changes. Use with caution in production environments.
A procedural macro that enables dynamic execution of Rust code before and after function calls. Unlike typical procedural macros that are limited to compile-time code generation, this crate allows you to:
This is particularly useful for CLI applications where users need to customize command behavior by injecting their own code before or after execution. Common use cases include:
To build and test the project:
cargo build
cargo test -- --nocaption # this allows to see println in tests
Add this to your Cargo.toml:
[dependencies]
cli_hooks_rs = "0.1.0"
Usage with custom hooks:
// .hooks/pre.rs (end user injected code)
{
println!("Starting execution");
}
// .hooks/post.rs (end user injected code)
{
println!("Execution completed");
}
// main.rs (CLI app)
use cli_hooks_rs::with_hooks;
#[with_hooks]
fn some_function() -> i32 {
std::thread::sleep(std::time::Duration::from_secs(1));
42
}