pub enum Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug, {
Element(Element<NS, TAG, LEAF, ATT, VAL>),
Leaf(LEAF),
}
Expand description
represents a node in a virtual dom A node could be an element which can contain one or more children of nodes. A node could also be just a text node which contains a string
Much of the types are Generics
NS - is the type for the namespace, this will be &’static str when used in html based virtual dom implementation TAG - is the type for the element tag, this will be &’static str when used in html based virtual dom impmenentation ATT - is the type for the attribute name, this will be &’static str when used in html based virtual dom implementation VAL - is the type for the value of the attribute, this will be String, f64, or just another generics that suits the implementing library which used mt-dom for just dom-diffing purposes
Variants
Element(Element<NS, TAG, LEAF, ATT, VAL>)
Element variant of a virtual node
Leaf(LEAF)
A Leaf node
Implementations
sourceimpl<NS, TAG, LEAF, ATT, VAL> Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
impl<NS, TAG, LEAF, ATT, VAL> Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
sourcepub fn take_element(self) -> Option<Element<NS, TAG, LEAF, ATT, VAL>>
pub fn take_element(self) -> Option<Element<NS, TAG, LEAF, ATT, VAL>>
consume self and return the element if it is an element variant None if it is a text node
sourcepub fn as_element_mut(
&mut self
) -> Option<&mut Element<NS, TAG, LEAF, ATT, VAL>>
pub fn as_element_mut(
&mut self
) -> Option<&mut Element<NS, TAG, LEAF, ATT, VAL>>
Get a mutable reference to the element, if this node is an element node
sourcepub fn as_element_ref(&self) -> Option<&Element<NS, TAG, LEAF, ATT, VAL>>
pub fn as_element_ref(&self) -> Option<&Element<NS, TAG, LEAF, ATT, VAL>>
returns a reference to the element if this is an element node
sourcepub fn add_children(
self,
children: impl IntoIterator<Item = Node<NS, TAG, LEAF, ATT, VAL>>
) -> Self
pub fn add_children(
self,
children: impl IntoIterator<Item = Node<NS, TAG, LEAF, ATT, VAL>>
) -> Self
Consume a mutable self and add a children to this node it if is an element will have no effect if it is a text node. This is used in building the nodes in a builder pattern
sourcepub fn add_children_ref_mut(
&mut self,
children: impl IntoIterator<Item = Node<NS, TAG, LEAF, ATT, VAL>>
)
pub fn add_children_ref_mut(
&mut self,
children: impl IntoIterator<Item = Node<NS, TAG, LEAF, ATT, VAL>>
)
add children but not consume self
sourcepub fn add_attributes(
self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
) -> Self
pub fn add_attributes(
self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
) -> Self
add attributes to the node and returns itself this is used in view building
sourcepub fn add_attributes_ref_mut(
&mut self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
)
pub fn add_attributes_ref_mut(
&mut self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
)
add attributes using a mutable reference to self
sourcepub fn get_attributes(&self) -> Option<&[Attribute<NS, ATT, VAL>]>
pub fn get_attributes(&self) -> Option<&[Attribute<NS, ATT, VAL>]>
get the attributes of this node returns None if it is a text node
sourcepub fn tag(&self) -> Option<&TAG>
pub fn tag(&self) -> Option<&TAG>
returns the tag of this node if it is an element otherwise None if it is a text node
sourcepub fn get_children(&self) -> Option<&[Node<NS, TAG, LEAF, ATT, VAL>]>
pub fn get_children(&self) -> Option<&[Node<NS, TAG, LEAF, ATT, VAL>]>
return the children of this node if it is an element returns None if it is a text node
sourcepub fn get_children_count(&self) -> usize
pub fn get_children_count(&self) -> usize
Return the count of the children of this node
sourcepub fn children_mut(&mut self) -> Option<&mut [Node<NS, TAG, LEAF, ATT, VAL>]>
pub fn children_mut(&mut self) -> Option<&mut [Node<NS, TAG, LEAF, ATT, VAL>]>
return the children of this node if it is an element returns None if it is a text node
sourcepub fn swap_remove_child(
&mut self,
index: usize
) -> Node<NS, TAG, LEAF, ATT, VAL>
pub fn swap_remove_child(
&mut self,
index: usize
) -> Node<NS, TAG, LEAF, ATT, VAL>
Removes an child node from this element and returns it.
The removed child is replaced by the last child of the element’s children.
Panics
Panics if this is a text node
sourcepub fn swap_children(&mut self, a: usize, b: usize)
pub fn swap_children(&mut self, a: usize, b: usize)
sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the total number of nodes on this node tree, that is counting the direct and indirect child nodes of this node.
sourcepub fn descendant_node_count(&self) -> usize
pub fn descendant_node_count(&self) -> usize
only count the descendant node
sourcepub fn set_attributes_ref_mut(
&mut self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
)
pub fn set_attributes_ref_mut(
&mut self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
)
remove the existing attributes and set with the new value
sourcepub fn merge_attributes(
self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
) -> Self
pub fn merge_attributes(
self,
attributes: impl IntoIterator<Item = Attribute<NS, ATT, VAL>>
) -> Self
merge to existing attributes if the attribute name already exist
Trait Implementations
sourceimpl<NS: Clone, TAG: Clone, LEAF: Clone, ATT: Clone, VAL: Clone> Clone for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
impl<NS: Clone, TAG: Clone, LEAF: Clone, ATT: Clone, VAL: Clone> Clone for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
sourceimpl<NS: Debug, TAG: Debug, LEAF: Debug, ATT: Debug, VAL: Debug> Debug for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
impl<NS: Debug, TAG: Debug, LEAF: Debug, ATT: Debug, VAL: Debug> Debug for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
sourceimpl<NS: PartialEq, TAG: PartialEq, LEAF: PartialEq, ATT: PartialEq, VAL: PartialEq> PartialEq<Node<NS, TAG, LEAF, ATT, VAL>> for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
impl<NS: PartialEq, TAG: PartialEq, LEAF: PartialEq, ATT: PartialEq, VAL: PartialEq> PartialEq<Node<NS, TAG, LEAF, ATT, VAL>> for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
impl<NS, TAG, LEAF, ATT, VAL> StructuralPartialEq for Node<NS, TAG, LEAF, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
Auto Trait Implementations
impl<NS, TAG, LEAF, ATT, VAL> RefUnwindSafe for Node<NS, TAG, LEAF, ATT, VAL> where
ATT: RefUnwindSafe,
LEAF: RefUnwindSafe,
NS: RefUnwindSafe,
TAG: RefUnwindSafe,
VAL: RefUnwindSafe,
impl<NS, TAG, LEAF, ATT, VAL> Send for Node<NS, TAG, LEAF, ATT, VAL> where
ATT: Send,
LEAF: Send,
NS: Send,
TAG: Send,
VAL: Send,
impl<NS, TAG, LEAF, ATT, VAL> Sync for Node<NS, TAG, LEAF, ATT, VAL> where
ATT: Sync,
LEAF: Sync,
NS: Sync,
TAG: Sync,
VAL: Sync,
impl<NS, TAG, LEAF, ATT, VAL> Unpin for Node<NS, TAG, LEAF, ATT, VAL> where
ATT: Unpin,
LEAF: Unpin,
NS: Unpin,
TAG: Unpin,
VAL: Unpin,
impl<NS, TAG, LEAF, ATT, VAL> UnwindSafe for Node<NS, TAG, LEAF, ATT, VAL> where
ATT: UnwindSafe,
LEAF: UnwindSafe,
NS: UnwindSafe,
TAG: UnwindSafe,
VAL: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more