1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Handler registration — pairs route metadata with a type-erased Axum handler.
//!
//! The `#[orpc]` macro emits two `inventory::submit!` calls per handler:
//! 1. `HandlerMetadata` — for codegen (TypeScript contract)
//! 2. `HandlerRegistration` — for runtime (Axum router construction)
//!
//! ## State erasure
//!
//! Handlers that extract `State<T>` produce `MethodRouter<T>` which can't be
//! stored in a `static` alongside handlers with different state types.
//!
//! Solution: the factory receives the concrete state value as `Box<dyn Any + Send + Sync>`
//! and downcasts it internally, returning a fully state-erased `Router<()>`.
//! Each handler's factory knows its own state type `S` at macro expansion time.
use Router;
use Any;
use Arc;
/// Factory that builds a single-route `Router<()>` given the app state.
///
/// Receives state as type-erased `Arc<dyn Any + Send + Sync>`.
/// The macro emits a concrete factory that downcasts to the known `S` type.
pub type RouteFactory = fn ;
/// Pairs a route path + method with its type-erased Axum route factory.
///
/// Registered globally by the `#[orpc]` macro via `inventory::submit!`.
collect!;
/// Build an Axum `Router<()>` from all registered handlers.
///
/// `state` is passed type-erased; each handler's factory downcasts it to its
/// own expected state type.
///
/// # Example
///
/// ```no_run
/// let app = rorpc::registration::build_router(std::sync::Arc::new(()));
/// ```