1use topcoat_core::context::Cx;
2use topcoat_view::{NodeViewParts, PartsWriter, View};
3
4#[derive(Debug, Clone)]
5pub struct Expr<T> {
6 pub(crate) evaluated: T,
7 pub(crate) js: View,
8}
9
10impl<T> Expr<T> {
11 #[inline]
12 pub fn new(evaluated: T, js: View) -> Self {
13 Self { evaluated, js }
14 }
15
16 #[inline]
17 pub fn into_evaluated_and_js(self) -> (T, View) {
18 (self.evaluated, self.js)
19 }
20}
21
22impl<T> NodeViewParts for Expr<T>
23where
24 T: NodeViewParts,
25{
26 fn into_view_parts(self, cx: &Cx, parts: &mut PartsWriter<'_>) {
27 parts.push_promoted_str_unescaped(&"<!-- ::topcoat::expr::start(\"");
28 topcoat_view::internal::view(parts, self.js);
29 parts.push_promoted_str_unescaped(&"\") -->");
30 self.evaluated.into_view_parts(cx, parts);
31 parts.push_promoted_str_unescaped(&"<!-- ::topcoat::expr::end -->");
32 }
33}