Strongly typed, extensible event mediator. For more info and explanation, please see the docs.
```rust use mediatrix::synchronous::basic::*;
struct UserMessageRequest { msg: String, priority: u8, }
enum NotifyEvent { Ignore, SendEmail(String), SendTextMessage(String), }
impl RequestHandler
let mediator = BasicMediator::
mediator.send(UserMessageRequest { msg: String::from("Hello World"), priority: 0, });
mediator.send(UserMessageRequest { msg: String::from("Is Rust Memory Safe?"), priority: 2, });
mediator.send(UserMessageRequest { msg: String::from("New Rust Version"), priority: 8, });
// Prints: Ignored some Message mediator.next().ok(); // Prints: Send Email with Message: Is Rust Memory Safe? mediator.next().ok(); // Prints: Send SMS with Message: New Rust Version mediator.next().ok(); ```
Click to open the asynchronous version
```rust use mediatrix::asynchronous::basic::*; use asynctrait::asynctrait;
struct UserMessageRequest { msg: String, priority: u8, }
enum NotifyEvent { Ignore, SendEmail(String), SendTextMessage(String), }
impl AsyncRequestHandler
let asyncmediator = BasicAsyncMediator::
asyncstd::task::blockon(async { async_mediator.send(UserMessageRequest { msg: String::from("Hello World"), priority: 0, }).await;
async_mediator.send(UserMessageRequest {
msg: String::from("Is Rust Memory Safe?"),
priority: 2,
}).await;
async_mediator.send(UserMessageRequest {
msg: String::from("New Rust Version"),
priority: 8,
}).await;
async_mediator.next().await.ok();
async_mediator.next().await.ok();
async_mediator.next().await.ok();
}); ```
async
feature) mediators CxAwareMediator
(use async
feature, carries a struct of your choice)Feel free to open an issue/PR explaining possible improvements or changes.
Also, please do not hesitate and open an issue when needed. I am happy to help!