Merge pull request #1624 from Erithax/rename_into_node_traits

rename IntoDynNode and IntoTemplate traits
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-01-04 10:25:49 -08:00
commit c1d9553e49
3 files changed
+30 -30

No files matched your search

+25 -25
View File
@@ -682,52 +682,52 @@ pub trait IntoDynNode<'a, A = ()> {
/// Consume this item along with a scopestate and produce a DynamicNode /// Consume this item along with a scopestate and produce a DynamicNode
/// ///
/// You can use the bump alloactor of the scopestate to creat the dynamic node /// You can use the bump alloactor of the scopestate to creat the dynamic node
fn into_vnode(self, cx: &'a ScopeState) -> DynamicNode<'a>; fn into_dyn_node(self, cx: &'a ScopeState) -> DynamicNode<'a>;
} }
impl<'a> IntoDynNode<'a> for () { impl<'a> IntoDynNode<'a> for () {
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
DynamicNode::default() DynamicNode::default()
} }
} }
impl<'a> IntoDynNode<'a> for VNode<'a> { impl<'a> IntoDynNode<'a> for VNode<'a> {
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
DynamicNode::Fragment(_cx.bump().alloc([self])) DynamicNode::Fragment(_cx.bump().alloc([self]))
} }
} }
impl<'a> IntoDynNode<'a> for DynamicNode<'a> { impl<'a> IntoDynNode<'a> for DynamicNode<'a> {
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
self self
} }
} }
impl<'a, T: IntoDynNode<'a>> IntoDynNode<'a> for Option<T> { impl<'a, T: IntoDynNode<'a>> IntoDynNode<'a> for Option<T> {
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
match self { match self {
Some(val) => val.into_vnode(_cx), Some(val) => val.into_dyn_node(_cx),
None => DynamicNode::default(), None => DynamicNode::default(),
} }
} }
} }
impl<'a> IntoDynNode<'a> for &Element<'a> { impl<'a> IntoDynNode<'a> for &Element<'a> {
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
match self.as_ref() { match self.as_ref() {
Some(val) => val.clone().into_vnode(_cx), Some(val) => val.clone().into_dyn_node(_cx),
_ => DynamicNode::default(), _ => DynamicNode::default(),
} }
} }
} }
impl<'a, 'b> IntoDynNode<'a> for LazyNodes<'a, 'b> { impl<'a, 'b> IntoDynNode<'a> for LazyNodes<'a, 'b> {
fn into_vnode(self, cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, cx: &'a ScopeState) -> DynamicNode<'a> {
DynamicNode::Fragment(cx.bump().alloc([cx.render(self).unwrap()])) DynamicNode::Fragment(cx.bump().alloc([cx.render(self).unwrap()]))
} }
} }
impl<'a, 'b> IntoDynNode<'b> for &'a str { impl<'a, 'b> IntoDynNode<'b> for &'a str {
fn into_vnode(self, cx: &'b ScopeState) -> DynamicNode<'b> { fn into_dyn_node(self, cx: &'b ScopeState) -> DynamicNode<'b> {
DynamicNode::Text(VText { DynamicNode::Text(VText {
value: cx.bump().alloc_str(self), value: cx.bump().alloc_str(self),
id: Default::default(), id: Default::default(),
@@ -736,7 +736,7 @@ impl<'a, 'b> IntoDynNode<'b> for &'a str {
} }
impl IntoDynNode<'_> for String { impl IntoDynNode<'_> for String {
fn into_vnode(self, cx: &ScopeState) -> DynamicNode { fn into_dyn_node(self, cx: &ScopeState) -> DynamicNode {
DynamicNode::Text(VText { DynamicNode::Text(VText {
value: cx.bump().alloc_str(&self), value: cx.bump().alloc_str(&self),
id: Default::default(), id: Default::default(),
@@ -745,13 +745,13 @@ impl IntoDynNode<'_> for String {
} }
impl<'b> IntoDynNode<'b> for Arguments<'_> { impl<'b> IntoDynNode<'b> for Arguments<'_> {
fn into_vnode(self, cx: &'b ScopeState) -> DynamicNode<'b> { fn into_dyn_node(self, cx: &'b ScopeState) -> DynamicNode<'b> {
cx.text_node(self) cx.text_node(self)
} }
} }
impl<'a> IntoDynNode<'a> for &'a VNode<'a> { impl<'a> IntoDynNode<'a> for &'a VNode<'a> {
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
DynamicNode::Fragment(_cx.bump().alloc([VNode { DynamicNode::Fragment(_cx.bump().alloc([VNode {
parent: self.parent.clone(), parent: self.parent.clone(),
stable_id: self.stable_id.clone(), stable_id: self.stable_id.clone(),
@@ -764,24 +764,24 @@ impl<'a> IntoDynNode<'a> for &'a VNode<'a> {
} }
} }
pub trait IntoTemplate<'a> { pub trait IntoVNode<'a> {
fn into_template(self, _cx: &'a ScopeState) -> VNode<'a>; fn into_vnode(self, _cx: &'a ScopeState) -> VNode<'a>;
} }
impl<'a> IntoTemplate<'a> for VNode<'a> { impl<'a> IntoVNode<'a> for VNode<'a> {
fn into_template(self, _cx: &'a ScopeState) -> VNode<'a> { fn into_vnode(self, _cx: &'a ScopeState) -> VNode<'a> {
self self
} }
} }
impl<'a> IntoTemplate<'a> for Element<'a> { impl<'a> IntoVNode<'a> for Element<'a> {
fn into_template(self, cx: &'a ScopeState) -> VNode<'a> { fn into_vnode(self, cx: &'a ScopeState) -> VNode<'a> {
match self { match self {
Some(val) => val.into_template(cx), Some(val) => val.into_vnode(cx),
_ => VNode::empty(cx).unwrap(), _ => VNode::empty(cx).unwrap(),
} }
} }
} }
impl<'a, 'b> IntoTemplate<'a> for LazyNodes<'a, 'b> { impl<'a, 'b> IntoVNode<'a> for LazyNodes<'a, 'b> {
fn into_template(self, cx: &'a ScopeState) -> VNode<'a> { fn into_vnode(self, cx: &'a ScopeState) -> VNode<'a> {
cx.render(self).unwrap() cx.render(self).unwrap()
} }
} }
@@ -791,12 +791,12 @@ pub struct FromNodeIterator;
impl<'a, T, I> IntoDynNode<'a, FromNodeIterator> for T impl<'a, T, I> IntoDynNode<'a, FromNodeIterator> for T
where where
T: Iterator<Item = I>, T: Iterator<Item = I>,
I: IntoTemplate<'a>, I: IntoVNode<'a>,
{ {
fn into_vnode(self, cx: &'a ScopeState) -> DynamicNode<'a> { fn into_dyn_node(self, cx: &'a ScopeState) -> DynamicNode<'a> {
let mut nodes = bumpalo::collections::Vec::new_in(cx.bump()); let mut nodes = bumpalo::collections::Vec::new_in(cx.bump());
nodes.extend(self.into_iter().map(|node| node.into_template(cx))); nodes.extend(self.into_iter().map(|node| node.into_vnode(cx)));
match nodes.into_bump_slice() { match nodes.into_bump_slice() {
children if children.is_empty() => DynamicNode::default(), children if children.is_empty() => DynamicNode::default(),
+1 -1
View File
@@ -407,7 +407,7 @@ impl<'src> ScopeState {
/// Convert any item that implements [`IntoDynNode`] into a [`DynamicNode`] using the internal [`Bump`] allocator /// Convert any item that implements [`IntoDynNode`] into a [`DynamicNode`] using the internal [`Bump`] allocator
pub fn make_node<'c, I>(&'src self, into: impl IntoDynNode<'src, I> + 'c) -> DynamicNode { pub fn make_node<'c, I>(&'src self, into: impl IntoDynNode<'src, I> + 'c) -> DynamicNode {
into.into_vnode(self) into.into_dyn_node(self)
} }
/// Create a new [`Attribute`] from a name, value, namespace, and volatile bool /// Create a new [`Attribute`] from a name, value, namespace, and volatile bool
+4 -4
View File
@@ -126,7 +126,7 @@ impl ToTokens for BodyNode {
}), }),
BodyNode::RawExpr(exp) => tokens.append_all(quote! { BodyNode::RawExpr(exp) => tokens.append_all(quote! {
{ {
let ___nodes = (#exp).into_vnode(__cx); let ___nodes = (#exp).into_dyn_node(__cx);
___nodes ___nodes
} }
}), }),
@@ -145,7 +145,7 @@ impl ToTokens for BodyNode {
// And then we can return them into the dyn loop // And then we can return them into the dyn loop
tokens.append_all(quote! { tokens.append_all(quote! {
{ {
let ___nodes =(#expr).into_iter().map(|#pat| { #renderer }).into_vnode(__cx); let ___nodes =(#expr).into_iter().map(|#pat| { #renderer }).into_dyn_node(__cx);
___nodes ___nodes
} }
}) })
@@ -154,7 +154,7 @@ impl ToTokens for BodyNode {
if is_if_chain_terminated(chain) { if is_if_chain_terminated(chain) {
tokens.append_all(quote! { tokens.append_all(quote! {
{ {
let ___nodes = (#chain).into_vnode(__cx); let ___nodes = (#chain).into_dyn_node(__cx);
___nodes ___nodes
} }
}); });
@@ -211,7 +211,7 @@ impl ToTokens for BodyNode {
tokens.append_all(quote! { tokens.append_all(quote! {
{ {
let ___nodes = (#body).into_vnode(__cx); let ___nodes = (#body).into_dyn_node(__cx);
___nodes ___nodes
} }
}); });