Skip to content

yves-bonami/brazier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages