Skip to content

Repository files navigation

tackle

Crates.io downloads crates.io Build Status Crates.io MSRV Documentation MIT licensed codecov

Description

Tackle is a library which makes easy for developers plug a hook/interceptor/middleware solution in your async libraries and projects.

Install

Either run from command line:

cargo add tackle

Or add to your Cargo.toml:

tackle = { version = "0.1.0" }

Usage

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(())
}

License

MIT or Apache-2.0

Author

Rogerio Pereira Araujo rogerio.araujo@gmail.com

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages