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:
slhx agent
2026-05-26 00:26:42 +02:00
parent 4803d681d2
commit bc8534a768
5 changed files with 34 additions and 21 deletions
+12 -1
View File
@@ -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 {