| Crates.io | hookable |
| lib.rs | hookable |
| version | 0.1.1 |
| created_at | 2025-06-06 12:17:33.987452+00 |
| updated_at | 2025-06-06 12:18:47.853086+00 |
| description | A thread-safe hook system that allows registering and executing sync and async hooks. |
| homepage | |
| repository | https://github.com/malezjaa/hookable |
| max_upload_size | |
| id | 1702947 |
| size | 28,727 |
A thread-safe hook system that allows registering and executing sync and async hooks.
Hooks are functions that can be attached to named events and executed when those events are triggered.
You can assign both async and sync to the same name. If you do that you will always have to call it using call_async.
use std::time::Duration;
use tokio::time::sleep;
use hookable::Hookable;
fn main() {
let hookable = Hookable::new();
// Register a sync hook
hookable.hook("event", || println!("Sync hook executed"));
// Register an async hook
hookable.hook_async("event", || Box::pin(async {
sleep(Duration::from_millis(200)).await;
}));
// ❌ This won't work because one of the events has to be run using await.
// `HookableError::AsyncHookCalledSync` will be returned.
hookable.call("event").unwrap();
// ✅ This will work.
hookable.call_async("event").await.unwrap();
}
The JS version both inspires this crate and its name