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> From<MarkerLine> for Node<MSG>
impl<MSG> From<MarkerLine> for Node<MSG>
Source§fn from(ml: MarkerLine) -> Node<MSG>
fn from(ml: MarkerLine) -> 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.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.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.