Struct mt_dom::Element

source ·
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>
where Ns: PartialEq + Clone + Debug, Tag: PartialEq + Debug, Leaf: PartialEq + Clone + Debug, Att: PartialEq + Clone + Debug, Val: PartialEq + Clone + Debug,

source

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

source

pub fn add_attributes( &mut self, attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>> )

add attributes to this element

source

pub fn add_children( &mut self, children: impl IntoIterator<Item = Node<Ns, Tag, Leaf, Att, Val>> )

add children virtual node to this element

source

pub fn children(&self) -> &[Node<Ns, Tag, Leaf, Att, Val>]

returns a refernce to the children of this node

source

pub fn children_mut(&mut self) -> &mut [Node<Ns, Tag, Leaf, Att, Val>]

returns a mutable reference to the children of this node

source

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

source

pub fn swap_children(&mut self, a: usize, b: usize)

Swaps the 2 child node in this element

§Arguments
  • a - The index of the first child node
  • b - The index of the second child node
§Panics

Panics if both a and b are out of bounds

source

pub fn take_children(self) -> Vec<Node<Ns, Tag, Leaf, Att, Val>>

consume self and return the children

source

pub fn attributes(&self) -> &[Attribute<Ns, Att, Val>]

return a reference to the attribute of this element

source

pub fn take_attributes(self) -> Vec<Attribute<Ns, Att, Val>>

consume self and return the attributes

source

pub fn namespace(&self) -> Option<&Ns>

return the namespace of this element

source

pub fn tag(&self) -> &Tag

return the tag of this element

source

pub fn take_tag(self) -> Tag

consume self and return the tag of this element

source

pub fn set_tag(&mut self, tag: Tag)

change the tag of this element

source

pub fn remove_attribute(&mut self, key: &Att)

remove the attributes with this key

source

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

source

pub fn merge_attributes( &mut self, new_attrs: impl IntoIterator<Item = Attribute<Ns, Att, Val>> )

merge to existing attributes if it exist

source

pub fn attribute_value(&self, name: &Att) -> Option<Vec<&Val>>

return all the attribute values which the name &Att

Trait Implementations§

source§

impl<Ns, Tag, Leaf, Att, Val> Clone for Element<Ns, Tag, Leaf, Att, Val>
where Ns: PartialEq + Clone + Debug + Clone, Tag: PartialEq + Debug + Clone, Leaf: PartialEq + Clone + Debug + Clone, Att: PartialEq + Clone + Debug + Clone, Val: PartialEq + Clone + Debug + Clone,

source§

fn clone(&self) -> Element<Ns, Tag, Leaf, Att, Val>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Ns, Tag, Leaf, Att, Val> Debug for Element<Ns, Tag, Leaf, Att, Val>
where Ns: PartialEq + Clone + Debug + Debug, Tag: PartialEq + Debug + Debug, Leaf: PartialEq + Clone + Debug + Debug, Att: PartialEq + Clone + Debug + Debug, Val: PartialEq + Clone + Debug + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Ns, Tag, Leaf, Att, Val> Default for Element<Ns, Tag, Leaf, Att, Val>

source§

fn default() -> Element<Ns, Tag, Leaf, Att, Val>

Returns the “default value” for a type. Read more
source§

impl<Ns, Tag, Leaf, Att, Val> PartialEq for Element<Ns, Tag, Leaf, Att, Val>

source§

fn eq(&self, other: &Element<Ns, Tag, Leaf, Att, Val>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.