Tackle is a library which makes easy for developers plug a hook/interceptor/middleware solution in your async libraries and projects.
Either run from command line:
cargo add tackle
Or add to your Cargo.toml:
tackle = { version = "0.1.0" }use tackle::{Client, Hook, HookError};
struct Smartty {
name: String,
}
impl Hook<String, String> for Smartty {
type Result = Result<String, HookError>;
type Error = HookError;
async fn call(&self, input: String) -> Self::Result {
Ok(format!("{} {}", self.name, input))
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let smart = Smartty {
name: "Mark".to_string(),
};
let client = Client::<Smartty, String, String>::new(smart)
.chain_fn(|req, next| async move {
let output = next.call(req).await?;
Ok(format!("{} {}", output, "Holmes"))
});
let output = client.hook.call("Hello".to_string()).await?;
println!("{}", output); // Should print: Mark Hello Holmes
Ok(())
}MIT or Apache-2.0
Rogerio Pereira Araujo rogerio.araujo@gmail.com