Skip to main content

rama_http/protocols/html/rama_impls/
collections.rs

1//! `IntoHtml` for the rama-utils collection types — each element is
2//! rendered in turn and concatenated.
3
4use rama_utils::collections::{
5    NonEmptySmallVec,
6    smallvec::{Array, SmallVec},
7};
8
9use crate::protocols::html::core::IntoHtml;
10
11impl<A> IntoHtml for SmallVec<A>
12where
13    A: Array,
14    A::Item: IntoHtml,
15{
16    #[inline]
17    fn into_html(self) -> impl IntoHtml {
18        self
19    }
20    #[inline]
21    fn escape_and_write(self, buf: &mut String) {
22        for x in self {
23            x.escape_and_write(buf);
24        }
25    }
26    #[inline]
27    fn size_hint(&self) -> usize {
28        self.iter().map(IntoHtml::size_hint).sum()
29    }
30}
31
32impl<const N: usize, T> IntoHtml for NonEmptySmallVec<N, T>
33where
34    T: IntoHtml,
35    [T; N]: Array<Item = T>,
36{
37    #[inline]
38    fn into_html(self) -> impl IntoHtml {
39        self
40    }
41    #[inline]
42    fn escape_and_write(self, buf: &mut String) {
43        for x in self {
44            x.escape_and_write(buf);
45        }
46    }
47    #[inline]
48    fn size_hint(&self) -> usize {
49        let mut n = 0;
50        for x in self {
51            n += x.size_hint();
52        }
53        n
54    }
55}