feat(core): join safe html fragments
Let already-safe fragments compose without downgrading to String, and use it in the v0 page assembly example to keep rendered and lowered fragments typed at the boundary. req: html_safety/001 req: html_safety/002 req: component/003
This commit is contained in:
@@ -141,6 +141,20 @@ impl SafeHtml {
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn join(fragments: impl IntoIterator<Item = SafeHtml>) -> Self {
|
||||
fragments.into_iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<SafeHtml> for SafeHtml {
|
||||
fn from_iter<T: IntoIterator<Item = SafeHtml>>(iter: T) -> Self {
|
||||
let mut html = String::new();
|
||||
for fragment in iter {
|
||||
html.push_str(fragment.as_str());
|
||||
}
|
||||
Self(html)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for SafeHtml {
|
||||
|
||||
Reference in New Issue
Block a user