feat(axum): register checked handles
Add HandlerRegistry::register_handle for generated Handle<T> values and migrate examples away from passing raw numeric handle ids at registration sites. req: ceremony/004 req: public_api/001
This commit is contained in:
+12
-1
@@ -5,7 +5,7 @@ use axum::http::{header, request::Parts, HeaderMap, HeaderValue, Request, Respon
|
||||
use axum::response::sse::{Event, Sse};
|
||||
use axum::response::IntoResponse;
|
||||
use futures_util::{Stream, StreamExt};
|
||||
use slhx_core::{BuildFingerprint, EffectBatch, IntoEffect};
|
||||
use slhx_core::{BuildFingerprint, EffectBatch, Handle, IntoEffect};
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::Infallible;
|
||||
|
||||
@@ -262,6 +262,17 @@ impl HandlerRegistry {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn register_handle<I, E>(
|
||||
self,
|
||||
handle: Handle<I>,
|
||||
handler: impl Fn(InteractionForm) -> E + Send + Sync + 'static,
|
||||
) -> Self
|
||||
where
|
||||
E: IntoEffect,
|
||||
{
|
||||
self.register(handle.id().id, handler)
|
||||
}
|
||||
|
||||
pub fn dispatch(&self, form: InteractionForm) -> Result<EffectResponse, DispatchRejection> {
|
||||
let handle_id = form.handle_id;
|
||||
let Some(handler) = self.handlers.get(&handle_id) else {
|
||||
|
||||
Reference in New Issue
Block a user