Expand description
Static async mediator with generated command dispatch, event workers, and typed resource injection.
Applications define commands with MediCommand, annotate async handlers
with medi_handler, group routes in medi_module, and compose the
selected modules with mediator!. The generated mediator dispatches
commands directly to their handler and resolves handler resources from a
typed tuple; it does not use dynamic handler or resource registries.
§Commands
use medi_rs::{MediCommand, Result, medi_handler, medi_module, mediator};
#[derive(MediCommand)]
#[medi_command(return_type = String, error_type = medi_rs::Error)]
struct Greet;
#[medi_handler]
async fn greet(_: Greet) -> Result<String> {
Ok("hello".into())
}
medi_module! {
manifest greeting;
commands { Greet => greet; }
}
mediator! {
struct AppMediator {
event_queue_capacity: 16;
event_workers: 1;
modules: [greeting];
}
}
assert_eq!(AppMediator::new().send(Greet).await?, "hello");Commands default to a () response and core::convert::Infallible error.
Set return_type and error_type in #[medi_command(...)] for other
response and application-error types.
§Resources and events
Resources are ordinary Clone values listed in a module’s resources
section. They are passed to the generated new constructor and injected as
handler parameters before the message. Events are ordinary Clone + Send + 'static values listed in an events section. To process events, retain the
mediator in 'static storage and call its generated start method before
calling publish.
Enable one runtime feature for event processing: tokio, wasm, or
embassy. The features are mutually exclusive. Command-only mediators do
not need a runtime feature.
Re-exports§
pub use adapters::lifecycle::Lifecycle;pub use adapters::queue::EventQueue;pub use adapters::shutdown::ShutdownSignal;
Modules§
- adapters
- Runtime queue and task-spawn adapters for generated mediators.
Macros§
- medi_
module - Declare a reusable mediator registration manifest owned by a Rust module.
- mediator
- Compose module-owned mediator manifests into one application mediator.
Structs§
- Event
Handler Failure - Metadata about a failed asynchronous event-handler invocation.
Enums§
- Error
- Framework error for queue operations.
- Start
Error - Error returned when a mediator is started more than once.
- TryPublish
Error - Error returned by a non-blocking event publish attempt.
Traits§
- Command
- Command metadata used by generated mediators.
- Decorator
Next - Continuation supplied to a function decorator.
- Event
Failure Reporter - Observes failures from generated asynchronous event-handler dispatch.
Type Aliases§
- Result
- Framework result used by event publishing and queue operations.
Attribute Macros§
- medi_
handler - Generate a typed static-dispatch invoker for an async handler function.
- medi_
task - Generate a runtime task invoker with typed mediator resource injection.
Derive Macros§
- Medi
Command - Derive static command metadata for a command or query type.