Struct mt_dom::Element [−][src]
pub struct Element<NS, TAG, ATT, VAL, EVENT, MSG> { pub namespace: Option<NS>, pub tag: TAG, pub attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>, pub children: Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>, 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, EVENT, MSG>>
attributes for this element
children: Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>
children elements of this element
self_closing: bool
is the element has a self closing tag
Implementations
create a new instance of an element
add attributes to this element
add children virtual node to this element
returns a refernce to the children of this node
returns a mutable reference to the children of this node
consume self and return the children
return a reference to the attribute of this element
consume self and return the attributes
Note: using the #[derive(PartialEq)] needs EVENT and MSG to also be PartialEq.
The reason this is manually implemented is, so that EVENT and MSG doesn’t need to be PartialEq as it is part of the Callback objects and are not compared
remove the attributes with this key
remove the existing values of this attribute and add the new values
merge to existing attributes if it exist
pub fn map_callback<MSG2>(
self,
cb: Callback<MSG, MSG2>
) -> Element<NS, TAG, ATT, VAL, EVENT, MSG2> where
MSG2: 'static,
pub fn map_callback<MSG2>(
self,
cb: Callback<MSG, MSG2>
) -> Element<NS, TAG, ATT, VAL, EVENT, MSG2> where
MSG2: 'static,
map_callback the return of the callback from MSG to MSG2
Trait Implementations
Note: using the #[derive(Debug)] needs EVENT and MSG to also be Debug
The reason this is manually implemented is, so that EVENT and MSG doesn’t need to be Debug as it is part of the Callback objects and are not shown.
impl<NS, TAG, ATT, VAL, EVENT, MSG> StructuralPartialEq for Element<NS, TAG, ATT, VAL, EVENT, MSG>
Auto Trait Implementations
impl<NS, TAG, ATT, VAL, EVENT, MSG> !RefUnwindSafe for Element<NS, TAG, ATT, VAL, EVENT, MSG>
impl<NS, TAG, ATT, VAL, EVENT, MSG> Unpin for Element<NS, TAG, ATT, VAL, EVENT, MSG> where
ATT: Unpin,
NS: Unpin,
TAG: Unpin,
VAL: Unpin,
impl<NS, TAG, ATT, VAL, EVENT, MSG> !UnwindSafe for Element<NS, TAG, ATT, VAL, EVENT, MSG>
Blanket Implementations
Mutably borrows from an owned value. Read more