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
sourceimpl<NS, TAG, LEAF, ATT, VAL> 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,
impl<NS, TAG, LEAF, ATT, VAL> 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,
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 get_children(&self) -> &[Node<NS, TAG, LEAF, ATT, VAL>]
pub fn get_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 get_attributes(&self) -> &[Attribute<NS, ATT, VAL>]
pub fn get_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
Trait Implementations
sourceimpl<NS: Clone, TAG: Clone, LEAF: Clone, ATT: Clone, VAL: Clone> Clone for 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,
impl<NS: Clone, TAG: Clone, LEAF: Clone, ATT: Clone, VAL: Clone> Clone for 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,
sourceimpl<NS: Debug, TAG: Debug, LEAF: Debug, ATT: Debug, VAL: Debug> Debug for 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,
impl<NS: Debug, TAG: Debug, LEAF: Debug, ATT: Debug, VAL: Debug> Debug for 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,
sourceimpl<NS: Default, TAG: Default, LEAF: Default, ATT: Default, VAL: Default> Default for 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,
impl<NS: Default, TAG: Default, LEAF: Default, ATT: Default, VAL: Default> Default for 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,
sourceimpl<NS: PartialEq, TAG: PartialEq, LEAF: PartialEq, ATT: PartialEq, VAL: PartialEq> PartialEq<Element<NS, TAG, LEAF, ATT, VAL>> for 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,
impl<NS: PartialEq, TAG: PartialEq, LEAF: PartialEq, ATT: PartialEq, VAL: PartialEq> PartialEq<Element<NS, TAG, LEAF, ATT, VAL>> for 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,
impl<NS, TAG, LEAF, ATT, VAL> StructuralPartialEq for 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,
Auto Trait Implementations
impl<NS, TAG, LEAF, ATT, VAL> RefUnwindSafe for Element<NS, TAG, LEAF, ATT, VAL> where
ATT: RefUnwindSafe,
LEAF: RefUnwindSafe,
NS: RefUnwindSafe,
TAG: RefUnwindSafe,
VAL: RefUnwindSafe,
impl<NS, TAG, LEAF, ATT, VAL> Send for Element<NS, TAG, LEAF, ATT, VAL> where
ATT: Send,
LEAF: Send,
NS: Send,
TAG: Send,
VAL: Send,
impl<NS, TAG, LEAF, ATT, VAL> Sync for Element<NS, TAG, LEAF, ATT, VAL> where
ATT: Sync,
LEAF: Sync,
NS: Sync,
TAG: Sync,
VAL: Sync,
impl<NS, TAG, LEAF, ATT, VAL> Unpin for Element<NS, TAG, LEAF, ATT, VAL> where
ATT: Unpin,
LEAF: Unpin,
NS: Unpin,
TAG: Unpin,
VAL: Unpin,
impl<NS, TAG, LEAF, ATT, VAL> UnwindSafe for Element<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