pachy-core 0.1.0

Core traits and types for the Pachycephalosaurus web framework
Documentation
use crate::{Props, Result};

#[derive(Debug, Clone, Default)]
pub struct RenderContext {
    pub props: Props,
    pub path: String,
    pub params: std::collections::HashMap<String, String>,
}

impl RenderContext {
    pub fn new(path: impl Into<String>) -> Self {
        Self {
            path: path.into(),
            ..Default::default()
        }
    }
}

#[derive(Debug, Clone)]
pub struct RenderedNode {
    pub html: String,
}

impl RenderedNode {
    pub fn new(html: impl Into<String>) -> Self {
        Self { html: html.into() }
    }

    pub fn into_html(self) -> String {
        self.html
    }
}

pub trait Component: Send + Sync {
    fn render(&self, ctx: &RenderContext) -> Result<RenderedNode>;

    fn name(&self) -> &'static str {
        std::any::type_name::<Self>()
    }
}