1use crate::{Props, Result};
2
3#[derive(Debug, Clone, Default)]
4pub struct RenderContext {
5 pub props: Props,
6 pub path: String,
7 pub params: std::collections::HashMap<String, String>,
8}
9
10impl RenderContext {
11 pub fn new(path: impl Into<String>) -> Self {
12 Self {
13 path: path.into(),
14 ..Default::default()
15 }
16 }
17}
18
19#[derive(Debug, Clone)]
20pub struct RenderedNode {
21 pub html: String,
22}
23
24impl RenderedNode {
25 pub fn new(html: impl Into<String>) -> Self {
26 Self { html: html.into() }
27 }
28
29 pub fn into_html(self) -> String {
30 self.html
31 }
32}
33
34pub trait Component: Send + Sync {
35 fn render(&self, ctx: &RenderContext) -> Result<RenderedNode>;
36
37 fn name(&self) -> &'static str {
38 std::any::type_name::<Self>()
39 }
40}