pub enum Node<MSG> {
Element(Element<MSG>),
Leaf(Leaf<MSG>),
}
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
Namespace - 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 AttributeName - is the type for the attribute name, this will be &’static str when used in html based virtual dom implementation AttributeValue - 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§
Implementations§
source§impl<MSG> Node<MSG>
impl<MSG> Node<MSG>
sourcepub fn render_with_indent(
&self,
buffer: &mut dyn Write,
indent: usize,
compressed: bool
) -> Result<(), Error>
pub fn render_with_indent( &self, buffer: &mut dyn Write, indent: usize, compressed: bool ) -> Result<(), Error>
render the node to a writable buffer
sourcepub fn render(&self, buffer: &mut dyn Write) -> Result<(), Error>
pub fn render(&self, buffer: &mut dyn Write) -> Result<(), Error>
render the node to a writable buffer
sourcepub fn render_to_string(&self) -> String
pub fn render_to_string(&self) -> String
render compressed html to string
sourcepub fn render_to_string_pretty(&self) -> String
pub fn render_to_string_pretty(&self) -> String
render to string with nice indention
source§impl<MSG> Node<MSG>
impl<MSG> Node<MSG>
sourcepub fn take_element(self) -> Option<Element<MSG>>
pub fn take_element(self) -> Option<Element<MSG>>
consume self and return the element if it is an element variant None if it is a text node
sourcepub fn leaf(&self) -> Option<&Leaf<MSG>>
pub fn leaf(&self) -> Option<&Leaf<MSG>>
returns a reference to the Leaf if the node is a Leaf variant
sourcepub fn is_element(&self) -> bool
pub fn is_element(&self) -> bool
returns true if the node is an element variant
sourcepub fn element_mut(&mut self) -> Option<&mut Element<MSG>>
pub fn element_mut(&mut self) -> Option<&mut Element<MSG>>
Get a mutable reference to the element, if this node is an element node
sourcepub fn element_ref(&self) -> Option<&Element<MSG>>
pub fn element_ref(&self) -> Option<&Element<MSG>>
returns a reference to the element if this is an element node
sourcepub fn with_children(
self,
children: impl IntoIterator<Item = Node<MSG>>
) -> Node<MSG>
pub fn with_children( self, children: impl IntoIterator<Item = Node<MSG>> ) -> Node<MSG>
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(
&mut self,
children: impl IntoIterator<Item = Node<MSG>>
) -> Result<(), Error>
pub fn add_children( &mut self, children: impl IntoIterator<Item = Node<MSG>> ) -> Result<(), Error>
add children but not consume self
sourcepub fn with_attributes(
self,
attributes: impl IntoIterator<Item = Attribute<MSG>>
) -> Node<MSG>
pub fn with_attributes( self, attributes: impl IntoIterator<Item = Attribute<MSG>> ) -> Node<MSG>
add attributes to the node and returns itself this is used in view building
sourcepub fn add_attributes(
&mut self,
attributes: impl IntoIterator<Item = Attribute<MSG>>
) -> Result<(), Error>
pub fn add_attributes( &mut self, attributes: impl IntoIterator<Item = Attribute<MSG>> ) -> Result<(), Error>
add attributes using a mutable reference to self
sourcepub fn attributes(&self) -> Option<&[Attribute<MSG>]>
pub fn attributes(&self) -> Option<&[Attribute<MSG>]>
get the attributes of this node returns None if it is a text node
sourcepub fn tag(&self) -> Option<&&'static str>
pub fn tag(&self) -> Option<&&'static str>
returns the tag of this node if it is an element otherwise None if it is a text node
sourcepub fn children(&self) -> &[Node<MSG>]
pub fn children(&self) -> &[Node<MSG>]
return the children of this node if it is an element returns None if it is a text node
sourcepub fn children_count(&self) -> usize
pub fn children_count(&self) -> usize
Return the count of the children of this node
sourcepub fn children_mut(&mut self) -> Option<&mut [Node<MSG>]>
pub fn children_mut(&mut self) -> Option<&mut [Node<MSG>]>
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<MSG>
pub fn swap_remove_child(&mut self, index: usize) -> Node<MSG>
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(
&mut self,
attributes: impl IntoIterator<Item = Attribute<MSG>>
) -> Result<(), Error>
pub fn set_attributes( &mut self, attributes: impl IntoIterator<Item = Attribute<MSG>> ) -> Result<(), Error>
remove the existing attributes and set with the new value
sourcepub fn merge_attributes(
self,
attributes: impl IntoIterator<Item = Attribute<MSG>>
) -> Node<MSG>
pub fn merge_attributes( self, attributes: impl IntoIterator<Item = Attribute<MSG>> ) -> Node<MSG>
merge to existing attributes if the attribute name already exist
sourcepub fn attribute_value(
&self,
name: &&'static str
) -> Option<Vec<&AttributeValue<MSG>>>
pub fn attribute_value( &self, name: &&'static str ) -> Option<Vec<&AttributeValue<MSG>>>
return the attribute values of this node which match the attribute name name
sourcepub fn first_value(&self, att_name: &&'static str) -> Option<&Value>
pub fn first_value(&self, att_name: &&'static str) -> Option<&Value>
get the first value of the attribute which has the name att_name
of this node
sourcepub fn unwrap_template(self) -> Node<MSG>
pub fn unwrap_template(self) -> Node<MSG>
sourcepub fn unwrap_template_ref(&self) -> &Node<MSG>
pub fn unwrap_template_ref(&self) -> &Node<MSG>
sourcepub fn is_template(&self) -> bool
pub fn is_template(&self) -> bool
returns true if this node is a templated view
Trait Implementations§
source§impl<MSG> PartialEq for Node<MSG>
impl<MSG> PartialEq for Node<MSG>
impl<MSG> Eq for Node<MSG>
Auto Trait Implementations§
impl<MSG> Freeze for Node<MSG>
impl<MSG> !RefUnwindSafe for Node<MSG>
impl<MSG> !Send for Node<MSG>
impl<MSG> !Sync for Node<MSG>
impl<MSG> Unpin for Node<MSG>
impl<MSG> !UnwindSafe for Node<MSG>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.