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
/// This module provides traits that help users define how their types should be rendered.
/// Implementation for primitive types are also provided.
use super::{Nodes, StaticNodes};
use crate::component::Component;

pub trait Render<C: Component> {
    fn render(self, nodes: Nodes<C>);
}

pub trait StaticRender<C: Component> {
    fn render(self, nodes: StaticNodes<C>);
}

macro_rules! impl_render_with_to_string {
    ($($type:ident)+) => {
        $(
            impl<C: Component> Render<C> for $type {
                fn render(self, nodes: Nodes<C>) {
                    nodes.update_text(&self.to_string());
                }
            }

            impl<C: Component> StaticRender<C> for $type {
                fn render(self, nodes: StaticNodes<C>) {
                    nodes.static_text(&self.to_string());
                }
            }
        )+
    }
}

impl_render_with_to_string! {
    i8 i16 i32 i64 u8 u16 u32 u64 isize usize f32 f64 bool char
}

impl<C: Component> StaticRender<C> for &str {
    fn render(self, nodes: StaticNodes<C>) {
        nodes.static_text(self);
    }
}

impl<C: Component> StaticRender<C> for &String {
    fn render(self, nodes: StaticNodes<C>) {
        nodes.static_text(self);
    }
}

impl<C: Component> StaticRender<C> for String {
    fn render(self, nodes: StaticNodes<C>) {
        nodes.static_text(&self);
    }
}

impl<C: Component> Render<C> for &str {
    fn render(self, nodes: Nodes<C>) {
        nodes.update_text(self);
    }
}

impl<C: Component> Render<C> for &String {
    fn render(self, nodes: Nodes<C>) {
        nodes.update_text(self);
    }
}

impl<C: Component> Render<C> for String {
    fn render(self, nodes: Nodes<C>) {
        nodes.update_text(&self);
    }
}

pub trait ElementRender<C: Component> {
    const ELEMENT_TAG: &'static str;
    fn render(self, item: crate::Element<C>);
}