feat: enable arbitrary body in rsx! macro

This commit is contained in:
Jonathan Kelley committed 2021-07-07 18:17:00 -04:00
1 parent fd7933561f
commit 7aec40d57e
38 files changed
+142 -88

No files matched your search

+12 -12
View File
@@ -16,18 +16,6 @@ pub enum Node {
RawExpr(Expr),
}
impl ToTokens for Node {
fn to_tokens(&self, tokens: &mut TokenStream2) {
match &self {
Node::Element(el) => el.to_tokens(tokens),
Node::Text(txt) => txt.to_tokens(tokens),
Node::RawExpr(exp) => tokens.append_all(quote! {
__cx.fragment_from_iter(#exp)
}),
}
}
}
impl Parse for Node {
fn parse(stream: ParseStream) -> Result<Self> {
// Supposedly this approach is discouraged due to inability to return proper errors
@@ -47,6 +35,18 @@ impl Parse for Node {
}
}
impl ToTokens for Node {
fn to_tokens(&self, tokens: &mut TokenStream2) {
match &self {
Node::Element(el) => el.to_tokens(tokens),
Node::Text(txt) => txt.to_tokens(tokens),
Node::RawExpr(exp) => tokens.append_all(quote! {
__cx.fragment_from_iter(#exp)
}),
}
}
}
// =======================================
// Parse just plain text
// =======================================