Enum sauron::vdom::Node

source ·
pub enum Node<MSG> {
    Element(Element<MSG>),
    Leaf(Leaf<MSG>),
}
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

Namespace - 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 AttributeName - is the type for the attribute name, this will be &’static str when used in html based virtual dom implementation AttributeValue - 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<MSG>)

Element variant of a virtual node

§

Leaf(Leaf<MSG>)

A Leaf node

Implementations§

source§

impl<MSG> Node<MSG>

source

pub fn map_msg<F, MSG2>(self, cb: F) -> Node<MSG2>
where F: Fn(MSG) -> MSG2 + Clone + 'static, MSG2: 'static, MSG: 'static,

map the msg of this node such that Node becomes Node

source§

impl<MSG> Node<MSG>

source

pub fn render_with_indent( &self, buffer: &mut dyn Write, indent: usize, compressed: bool ) -> Result<(), Error>

render the node to a writable buffer

source

pub fn render(&self, buffer: &mut dyn Write) -> Result<(), Error>

render the node to a writable buffer

source

pub fn render_to_string(&self) -> String

render compressed html to string

source

pub fn render_to_string_pretty(&self) -> String

render to string with nice indention

source§

impl<MSG> Node<MSG>

source

pub fn take_element(self) -> Option<Element<MSG>>

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<MSG>>

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_text(&self) -> bool

returns true if this is a text node

source

pub fn as_text(&self) -> Option<&str>

return the text if this is text node leaf

source

pub fn as_symbol(&self) -> Option<&str>

return the html entity if it is a symbol variant

source

pub fn element_mut(&mut self) -> Option<&mut Element<MSG>>

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

source

pub fn element_ref(&self) -> Option<&Element<MSG>>

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

source

pub fn with_children( self, children: impl IntoIterator<Item = Node<MSG>> ) -> Node<MSG>

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<MSG>> ) -> Result<(), Error>

add children but not consume self

source

pub fn with_attributes( self, attributes: impl IntoIterator<Item = Attribute<MSG>> ) -> Node<MSG>

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<MSG>> ) -> Result<(), Error>

add attributes using a mutable reference to self

source

pub fn attributes(&self) -> Option<&[Attribute<MSG>]>

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

source

pub fn tag(&self) -> Option<&&'static str>

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<MSG>]

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<MSG>]>

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<MSG>

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<MSG>> ) -> Result<(), Error>

remove the existing attributes and set with the new value

source

pub fn merge_attributes( self, attributes: impl IntoIterator<Item = Attribute<MSG>> ) -> Node<MSG>

merge to existing attributes if the attribute name already exist

source

pub fn attribute_value( &self, name: &&'static str ) -> Option<Vec<&AttributeValue<MSG>>>

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

source

pub fn first_value(&self, att_name: &&'static str) -> Option<&Value>

get the first value of the attribute which has the name att_name of this node

source

pub fn skip_diff(&self) -> Option<SkipDiff>

return the skip diff if this node has one

source

pub fn unwrap_template(self) -> Node<MSG>

source

pub fn unwrap_template_ref(&self) -> &Node<MSG>

source

pub fn is_template(&self) -> bool

returns true if this node is a templated view

Trait Implementations§

source§

impl<MSG> Clone for Node<MSG>

source§

fn clone(&self) -> Node<MSG>

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<MSG> Debug for Node<MSG>

source§

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

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

impl<MSG> PartialEq for Node<MSG>

source§

fn eq(&self, __other: &Node<MSG>) -> 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<MSG> Eq for Node<MSG>

Auto Trait Implementations§

§

impl<MSG> Freeze for Node<MSG>

§

impl<MSG> !RefUnwindSafe for Node<MSG>

§

impl<MSG> !Send for Node<MSG>

§

impl<MSG> !Sync for Node<MSG>

§

impl<MSG> Unpin for Node<MSG>

§

impl<MSG> !UnwindSafe for Node<MSG>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.