Enum 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> From<Arc> for Node<MSG>

Source§

fn from(arc: Arc) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<CellText> for Node<MSG>

Source§

fn from(ct: CellText) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<Circle> for Node<MSG>

Source§

fn from(c: Circle) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<Fragment> for Node<MSG>

Source§

fn from(fragment: Fragment) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<Line> for Node<MSG>

Source§

fn from(line: Line) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<MarkerLine> for Node<MSG>

Source§

fn from(ml: MarkerLine) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<Polygon> for Node<MSG>

Source§

fn from(pl: Polygon) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<Rect> for Node<MSG>

Source§

fn from(r: Rect) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> From<Text> for Node<MSG>

Source§

fn from(t: Text) -> Node<MSG>

Converts to this type from the input type.
Source§

impl<MSG> PartialEq for Node<MSG>

Source§

fn eq(&self, __other: &Node<MSG>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

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

Source§

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

Source§

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.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,