Trait dendrite_auth::dendrite::axon_utils::HandlerRegistry
source · pub trait HandlerRegistry<P, M, W>: Send {
// Required methods
fn register(
&mut self,
applicator: &'static dyn Fn(&mut Self) -> Result<(), Error>
) -> Result<(), Error>;
fn insert<T>(
&mut self,
name: &str,
deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync),
handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> + Sync)
) -> Result<(), Error>
where T: Send + Clone;
fn insert_handle(
&mut self,
handle: Box<dyn SubscriptionHandle<P, M, W>>
) -> Result<(), Error>;
fn insert_ignoring_output<T, R>(
&mut self,
name: &str,
deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync),
handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<Option<R>, Error>> + Send>> + Sync)
) -> Result<(), Error>
where T: Send + Clone,
R: Clone;
fn insert_with_output<T>(
&mut self,
name: &str,
deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync),
handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<Option<W>, Error>> + Send>> + Sync)
) -> Result<(), Error>
where T: Send + Clone;
fn insert_with_mapped_output<T, R>(
&mut self,
name: &str,
deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync),
handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<Option<R>, Error>> + Send>> + Sync),
type_name: &str,
wrapper: &'static (dyn Fn(&str, &R) -> Result<W, Error> + Sync)
) -> Result<(), Error>
where T: Send + Clone,
R: Clone;
fn append_category_handle(
&mut self,
regex: &str,
handle: Box<dyn SubscriptionHandle<P, M, W>>
) -> Result<(), Error>;
fn get(&self, name: &str) -> Option<&dyn SubscriptionHandle<P, M, W>>;
}
Expand description
Describes a registry for handlers for a particular type projection (or context) and a particular return type.
I tried to make it possible to pass an async fn
directly to parameter handler
, but the return
type after desugaring is unnameable
(https://internals.rust-lang.org/t/naming-the-return-type-of-an-async-function/10085).
So it has to be wrapped in a closure that Box::pin
s the return value, like this:
async fn handle_greet_command(command: GreetCommand) -> anyhow::Result<()> {
Ok(())
}
let mut handler_registry: TheHandlerRegistry<Projection,Model,Option<Projection>> = empty_handler_registry();
let result = handler_registry.insert(
"GreetCommand",
&GreetCommand::decode,
&(|c, _: Model, _: Projection| Box::pin(handle_greet_command(c)))
);
assert!(result.is_ok());
P: type of the projection that serves as context for the handlers M: type of the model (e.g., kind of aggregate, or query model; this typically contains a way to connect to an external service for persistence or delegation) W: type of the wrapped result
Required Methods§
fn register( &mut self, applicator: &'static dyn Fn(&mut Self) -> Result<(), Error> ) -> Result<(), Error>
fn insert<T>( &mut self, name: &str, deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync), handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> + Sync) ) -> Result<(), Error>
fn insert_handle( &mut self, handle: Box<dyn SubscriptionHandle<P, M, W>> ) -> Result<(), Error>
fn insert_ignoring_output<T, R>( &mut self, name: &str, deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync), handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<Option<R>, Error>> + Send>> + Sync) ) -> Result<(), Error>
fn insert_with_output<T>( &mut self, name: &str, deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync), handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<Option<W>, Error>> + Send>> + Sync) ) -> Result<(), Error>
fn insert_with_mapped_output<T, R>( &mut self, name: &str, deserializer: &'static (dyn Fn(Bytes) -> Result<T, DecodeError> + Sync), handler: &'static (dyn Fn(T, M, P) -> Pin<Box<dyn Future<Output = Result<Option<R>, Error>> + Send>> + Sync), type_name: &str, wrapper: &'static (dyn Fn(&str, &R) -> Result<W, Error> + Sync) ) -> Result<(), Error>
fn append_category_handle( &mut self, regex: &str, handle: Box<dyn SubscriptionHandle<P, M, W>> ) -> Result<(), Error>
fn get(&self, name: &str) -> Option<&dyn SubscriptionHandle<P, M, W>>
Object Safety§
This trait is not object safe.