Crates.io | brazier |
lib.rs | brazier |
version | 0.1.0 |
source | src |
created_at | 2022-03-07 08:06:19.04533 |
updated_at | 2023-04-26 07:33:03.548658 |
description | A mediator implementation in Rust, heavily inspired by the .NET MediatR package (https://github.com/jbogard/MediatR). |
homepage | https://github.com/yves-bonami/brazier |
repository | https://github.com/yves-bonami/brazier |
max_upload_size | |
id | 544888 |
size | 15,494 |
An implemenation of the mediator pattern.
Brazier is heavily inspired by the .NET MediatR pacakage. It allows you to decouple the sending of a message and the handling of it.
use brazier::*;
pub struct Ping {}
impl Request<String> for Ping {}
#[derive(Debug)]
pub struct PingHandler;
#[async_trait::async_trait]
impl RequestHandler<Ping, String> for PingHandler {
async fn handle(&mut self, _request: Ping) -> Result<String> {
Ok(String::from("pong!"))
}
}
#[tokio::main]
async fn main() -> Result<()> {
let mut mediator = Mediator::new();
mediator.register_handler(PingHandler);
let result = mediator.send(Ping {}).await?;
println!("{}", result);
Ok(())
}