Skip to main content

basecoat_core/
children.rs

1use std::borrow::Cow;
2use std::fmt;
3
4use crate::Markup;
5
6/// Pre-rendered inner HTML produced by `rsx!`.
7///
8/// Phase 2c (`rsx!`) will produce `Children` values by recursively rendering
9/// inner nodes.  You can also build them directly from strings or `Markup`.
10#[derive(Clone, Debug, PartialEq, Eq, Default)]
11pub struct Children(pub Cow<'static, str>);
12
13impl Children {
14    /// An empty children fragment (allocates nothing).
15    pub fn empty() -> Self {
16        Children(Cow::Borrowed(""))
17    }
18}
19
20impl fmt::Display for Children {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        f.write_str(&self.0)
23    }
24}
25
26impl From<String> for Children {
27    fn from(s: String) -> Self {
28        Children(Cow::Owned(s))
29    }
30}
31
32impl From<&'static str> for Children {
33    fn from(s: &'static str) -> Self {
34        Children(Cow::Borrowed(s))
35    }
36}
37
38impl From<Markup> for Children {
39    fn from(m: Markup) -> Self {
40        Children(m.0)
41    }
42}