pub struct Element<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,{
pub namespace: Option<Ns>,
pub tag: Tag,
pub attrs: Vec<Attribute<Ns, Att, Val>>,
pub children: Vec<Node<Ns, Tag, Leaf, Att, Val>>,
pub self_closing: bool,
}
Expand description
Represents an element of the virtual node
An element has a generic tag, this tag could be a static str tag, such as usage in html dom.
Example of which are div
, a
, input
, img
, etc.
Tag is a generic type, which can represent a different DOM tree other than the html dom
such as widgets in native platform such as gtk, example of which are Hpane
, Vbox
, Image
,
An element can have an optional namespace, such in the case for html dom where namespace like HTML and SVG, which needs to specified in order to create the DOM element to work on the browser.
The namespace is also needed in attributes where namespace are necessary such as xlink:href
where the namespace xlink
is needed in order for the linked element in an svg image to work.
Fields§
§namespace: Option<Ns>
namespace of this element, svg elements requires namespace to render correcly in the browser
tag: Tag
the element tag, such as div, a, button
attrs: Vec<Attribute<Ns, Att, Val>>
attributes for this element
children: Vec<Node<Ns, Tag, Leaf, Att, Val>>
children elements of this element
self_closing: bool
is the element has a self closing tag
Implementations§
source§impl<Ns, Tag, Leaf, Att, Val> Element<Ns, Tag, Leaf, Att, Val>
impl<Ns, Tag, Leaf, Att, Val> Element<Ns, Tag, Leaf, Att, Val>
sourcepub fn new(
namespace: Option<Ns>,
tag: Tag,
attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>>,
children: impl IntoIterator<Item = Node<Ns, Tag, Leaf, Att, Val>>,
self_closing: bool
) -> Self
pub fn new( namespace: Option<Ns>, tag: Tag, attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>>, children: impl IntoIterator<Item = Node<Ns, Tag, Leaf, Att, Val>>, self_closing: bool ) -> Self
create a new instance of an element
sourcepub fn add_attributes(
&mut self,
attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>>
)
pub fn add_attributes( &mut self, attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>> )
add attributes to this element
sourcepub fn add_children(
&mut self,
children: impl IntoIterator<Item = Node<Ns, Tag, Leaf, Att, Val>>
)
pub fn add_children( &mut self, children: impl IntoIterator<Item = Node<Ns, Tag, Leaf, Att, Val>> )
add children virtual node to this element
sourcepub fn children(&self) -> &[Node<Ns, Tag, Leaf, Att, Val>]
pub fn children(&self) -> &[Node<Ns, Tag, Leaf, Att, Val>]
returns a refernce to the children of this node
sourcepub fn children_mut(&mut self) -> &mut [Node<Ns, Tag, Leaf, Att, Val>]
pub fn children_mut(&mut self) -> &mut [Node<Ns, Tag, Leaf, Att, Val>]
returns a mutable reference to the children of this 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 index is out of bounds in children
sourcepub fn swap_children(&mut self, a: usize, b: usize)
pub fn swap_children(&mut self, a: usize, b: usize)
sourcepub fn take_children(self) -> Vec<Node<Ns, Tag, Leaf, Att, Val>>
pub fn take_children(self) -> Vec<Node<Ns, Tag, Leaf, Att, Val>>
consume self and return the children
sourcepub fn attributes(&self) -> &[Attribute<Ns, Att, Val>]
pub fn attributes(&self) -> &[Attribute<Ns, Att, Val>]
return a reference to the attribute of this element
sourcepub fn take_attributes(self) -> Vec<Attribute<Ns, Att, Val>>
pub fn take_attributes(self) -> Vec<Attribute<Ns, Att, Val>>
consume self and return the attributes
sourcepub fn remove_attribute(&mut self, key: &Att)
pub fn remove_attribute(&mut self, key: &Att)
remove the attributes with this key
sourcepub fn set_attributes(
&mut self,
attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>>
)
pub fn set_attributes( &mut self, attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>> )
remove the existing values of this attribute and add the new values
sourcepub fn merge_attributes(
&mut self,
new_attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>>
)
pub fn merge_attributes( &mut self, new_attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>> )
merge to existing attributes if it exist