Skip to main content

actr_framework/
service_handler.rs

1//! `ServiceHandler` — protoc-gen handler meta-trait.
2//!
3//! Every `{Service}Handler` trait emitted by `protoc-gen-actrframework`
4//! inherits from this trait and binds its `Workload` associated type to the
5//! code-generated `{Service}Workload<Self>` wrapper. The `entry!` macro (and
6//! anything else downstream of protoc-gen) can therefore recover the
7//! concrete `Workload` type from just the handler type — `W = <H as
8//! ServiceHandler>::Workload` — without re-deriving it by name mangling.
9//!
10//! Per Option U γ-unified §4.5 / Phase 6b `protoc-gen` design:
11//!
12//! ```rust,ignore
13//! // Generated
14//! pub trait EchoServiceHandler:
15//!     actr_framework::ServiceHandler<Workload = EchoServiceWorkload<Self>>
16//! { ... }
17//! ```
18//!
19//! The trait is deliberately minimal — the only thing it promises is the
20//! mapping from the user's domain-specific handler type to the
21//! `Workload`-implementing wrapper that `entry!` will eventually register.
22//! No runtime methods are added; `ServiceHandler` is a pure type-level
23//! associator.
24
25use crate::Workload;
26
27/// Associator trait emitted by protoc-gen: maps a user-implemented handler
28/// type to the generated `{Service}Workload<Self>` wrapper.
29///
30/// Users never implement this trait by hand; the generator's
31/// `{Service}Handler` trait expands into a super-trait bound on it so the
32/// framework can recover `type Workload` without name mangling.
33///
34/// # Design notes
35///
36/// - `MaybeSendSync + 'static` mirrors the bound on every
37///   `{Service}Handler`, so downstream generic code can compose
38///   `ServiceHandler` bounds into dispatcher-generic functions without
39///   re-stating the auto-trait marker.
40/// - The associated type pins a concrete `Workload` impl, not a `dyn
41///   Workload`. Static dispatch all the way down — matching the rest of
42///   the framework's zero-cost abstractions.
43pub trait ServiceHandler: crate::MaybeSendSync + 'static {
44    /// Concrete `Workload` wrapper for this handler.
45    ///
46    /// protoc-gen's `{Service}Handler` trait sets this to the generated
47    /// `{Service}Workload<Self>` wrapper, which carries the dispatcher
48    /// (via `type Dispatcher = {Service}Dispatcher<Self>`) and inherits
49    /// every observation-hook default from `Workload`.
50    type Workload: Workload;
51}