Enum mt_dom::Node

source ·
pub enum Node<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,
{ Element(Element<Ns, Tag, Leaf, Att, Val>), NodeList(Vec<Node<Ns, Tag, Leaf, Att, Val>>), Fragment(Vec<Node<Ns, Tag, Leaf, Att, Val>>), Leaf(Leaf), }
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

Ns - 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 Att - is the type for the attribute name, this will be &’static str when used in html based virtual dom implementation Val - 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§

§

Element(Element<Ns, Tag, Leaf, Att, Val>)

Element variant of a virtual node

§

NodeList(Vec<Node<Ns, Tag, Leaf, Att, Val>>)

A node containing nodes, this will be unrolled together with the rest of the children of the node

§

Fragment(Vec<Node<Ns, Tag, Leaf, Att, Val>>)

A document fragment node, will be created using fragment node and attached to the dom

§

Leaf(Leaf)

A Leaf node

Implementations§

source§

impl<Ns, Tag, Leaf, Att, Val> Node<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 take_element(self) -> Option<Element<Ns, Tag, Leaf, Att, Val>>

consume self and return the element if it is an element variant None if it is a text node

source

pub fn leaf(&self) -> Option<&Leaf>

returns a reference to the Leaf if the node is a Leaf variant

source

pub fn is_element(&self) -> bool

returns true if the node is an element variant

source

pub fn is_leaf(&self) -> bool

returns true if the node is a Leaf

source

pub fn is_fragment(&self) -> bool

returns true if the Node is a fragment variant

source

pub fn element_mut(&mut self) -> Option<&mut Element<Ns, Tag, Leaf, Att, Val>>

Get a mutable reference to the element, if this node is an element node

source

pub fn element_ref(&self) -> Option<&Element<Ns, Tag, Leaf, Att, Val>>

returns a reference to the element if this is an element node

source

pub fn with_children( self, children: impl IntoIterator<Item = Node<Ns, Tag, Leaf, Att, Val>> ) -> Self

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

source

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

add children but not consume self

source

pub fn with_attributes( self, attributes: impl IntoIterator<Item = Attribute<Ns, Att, Val>> ) -> Self

add attributes to the node and returns itself this is used in view building

source

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

add attributes using a mutable reference to self

source

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

get the attributes of this node returns None if it is a text node

source

pub fn tag(&self) -> Option<&Tag>

returns the tag of this node if it is an element otherwise None if it is a text node

source

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

return the children of this node if it is an element returns None if it is a text node

source

pub fn children_count(&self) -> usize

Return the count of the children of this node

source

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

return the children of this node if it is an element returns None if it is a text 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 this is a text node

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 Panics if this is a text node

source

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.

source

pub fn descendant_node_count(&self) -> usize

only count the descendant node

source

pub fn set_attributes( &mut self, attributes: impl IntoIterator<Item = Attribute<Ns, Att, Val>> ) -> Result<(), Error>

remove the existing attributes and set with the new value

source

pub fn merge_attributes( self, attributes: impl IntoIterator<Item = Attribute<Ns, Att, Val>> ) -> Self

merge to existing attributes if the attribute name already exist

source

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

returh the attribute values of this node which match the attribute name name

Trait Implementations§

source§

impl<Ns, Tag, Leaf, Att, Val> Clone for Node<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) -> Node<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 Node<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> PartialEq for Node<Ns, Tag, Leaf, Att, Val>

source§

fn eq(&self, other: &Node<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 Node<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 Node<Ns, Tag, Leaf, Att, Val>

§

impl<Ns, Tag, Leaf, Att, Val> Send for Node<Ns, Tag, Leaf, Att, Val>
where Att: Send, Leaf: Send, Ns: Send, Tag: Send, Val: Send,

§

impl<Ns, Tag, Leaf, Att, Val> Sync for Node<Ns, Tag, Leaf, Att, Val>
where Att: Sync, Leaf: Sync, Ns: Sync, Tag: Sync, Val: Sync,

§

impl<Ns, Tag, Leaf, Att, Val> Unpin for Node<Ns, Tag, Leaf, Att, Val>
where Att: Unpin, Leaf: Unpin, Ns: Unpin, Tag: Unpin, Val: Unpin,

§

impl<Ns, Tag, Leaf, Att, Val> UnwindSafe for Node<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.