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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Modular Frontend Engines & SSR Adapters for Rullst.
//!
//! Provides small HTML response wrappers used by Rullst frontend compatibility
//! profiles. These types do not install browser assets, establish a WebSocket
//! lifecycle, hydrate Wasm, load Pico.css, or render Tera templates by
//! themselves; those integrations remain explicit.
use axum::response::{Html, IntoResponse, Response};
/// Render adapter trait for frontend frameworks and components.
pub trait RenderAdapter: Send + Sync {
/// Renders the component view into an HTML string.
fn render_to_html(&self) -> String;
}
/// HTML adapter for raw HTML string responses (`rullst::html!`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HtmlAdapter(pub String);
impl IntoResponse for HtmlAdapter {
fn into_response(self) -> Response {
Html(self.0).into_response()
}
}
/// HTML response compatibility wrapper for a page that may load Pico.css.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PicoAdapter(pub String);
impl IntoResponse for PicoAdapter {
fn into_response(self) -> Response {
Html(self.0).into_response()
}
}
/// Compatibility alias for Topcoat adapter.
pub type TopcoatAdapter = PicoAdapter;
/// HTML response compatibility wrapper for output rendered by a template engine.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TemplateAdapter(pub String);
impl IntoResponse for TemplateAdapter {
fn into_response(self) -> Response {
Html(self.0).into_response()
}
}
/// HTML response wrapper; the LiveView WebSocket lifecycle is configured separately.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LiveViewAdapter<T> {
/// Inner component or live view state.
pub view: T,
}
impl<T: std::fmt::Display> LiveViewAdapter<T> {
/// Creates a new LiveView adapter.
pub fn new(view: T) -> Self {
Self { view }
}
}
impl<T: std::fmt::Display> IntoResponse for LiveViewAdapter<T> {
fn into_response(self) -> Response {
Html(self.view.to_string()).into_response()
}
}
/// HTML response wrapper for Wasm Island mount markup.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WasmIslandAdapter<T> {
/// Inner component or island markup.
pub component: T,
}
impl<T: std::fmt::Display> WasmIslandAdapter<T> {
/// Creates a new Wasm Island adapter.
pub fn new(component: T) -> Self {
Self { component }
}
}
impl<T: std::fmt::Display> IntoResponse for WasmIslandAdapter<T> {
fn into_response(self) -> Response {
Html(self.component.to_string()).into_response()
}
}
/// Compatibility alias for Leptos pattern views.
pub type LeptosAdapter<T> = LiveViewAdapter<T>;
/// Compatibility alias for Dioxus pattern components.
pub type DioxusAdapter<T> = WasmIslandAdapter<T>;