topcoat_runtime/router.rs
1#[cfg(feature = "router")]
2use topcoat_router::RouterBuilder;
3
4#[cfg(feature = "router")]
5use crate::RuntimeLayer;
6
7/// Marks a router's app context as configured for the browser runtime.
8#[derive(Debug, Clone, Copy)]
9pub struct RuntimeSetup;
10
11/// Sets up the browser runtime on a [`RouterBuilder`].
12#[cfg(feature = "router")]
13pub trait RouterBuilderRuntimeExt {
14 /// Enables page reruns by registering a [`RuntimeLayer`].
15 ///
16 /// Call this once when building a router that serves interactive pages.
17 /// Register your application's pathless layers first so the runtime
18 /// layer can rewrite page reruns to `GET` before those layers run.
19 /// See [`RuntimeLayer`] for the request format and rewrite behavior.
20 ///
21 /// Register procedures and shards separately through discovery or
22 /// explicit registration.
23 #[must_use]
24 fn runtime(self) -> Self;
25}
26
27#[cfg(feature = "router")]
28impl RouterBuilderRuntimeExt for RouterBuilder {
29 fn runtime(self) -> Self {
30 self.layer(RuntimeLayer).app_context(RuntimeSetup)
31 }
32}