#mediator #net #heavily #message #pattern #sending #decoupling

brazier

A mediator implementation in Rust, heavily inspired by the .NET MediatR package (https://github.com/jbogard/MediatR)

2 unstable releases

0.1.0 Apr 26, 2023
0.0.1 Mar 7, 2022

#5 in #heavily

23 downloads per month

MIT license

8KB
116 lines

Brazier

crates.io Rust

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.

Example

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

Dependencies

~335–790KB
~19K SLoC