Enum Node

Source
pub enum Node<T, ATT, EVENT, MSG>
where MSG: 'static, EVENT: 'static, ATT: Clone,
{ Element(Element<T, ATT, EVENT, MSG>), Text(Text), }
Expand description

This is the core data structure of the library. Any tree can be represented by Node. The T is generic instead of just using plain &'static str in order for this library to be used not only in html based widget but can also be used to represent native GUI widgets in various platforms.

Note: Clone is necessary for the aesthetics in the construction of node through series of function calls. Without Clone, the user code would look like these:

    div(&[class("some-class"), &[text("Some text")])

as compared to

    div([class("some-class"), [text("some text)])

Cloning is only done once, and happens when constructing the views into a node tree. Cloning also allows flexibility such as adding more children into an existing node/element.

Variants§

§

Element(Element<T, ATT, EVENT, MSG>)

Element variant of a virtual node

§

Text(Text)

Text variant of a virtual node

Implementations§

Source§

impl<T, ATT, EVENT, MSG> Node<T, ATT, EVENT, MSG>
where EVENT: 'static, MSG: 'static, ATT: PartialEq + Ord + ToString + Clone,

Source

pub fn map_msg<F, MSG2>(self, func: F) -> Node<T, ATT, EVENT, MSG2>
where F: Fn(MSG) -> MSG2 + 'static, MSG2: 'static,

map the msg of callback of this element node

Source

pub fn take_element(self) -> Option<Element<T, ATT, EVENT, MSG>>

consume the element

Source

pub fn as_element_mut(&mut self) -> Option<&mut Element<T, ATT, EVENT, MSG>>

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

Source

pub fn as_element_ref(&self) -> Option<&Element<T, ATT, EVENT, MSG>>

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

Source

pub fn add_children(self, children: Vec<Node<T, ATT, EVENT, MSG>>) -> Self

Append children to this element

Source

pub fn add_attributes(self, attributes: Vec<Attribute<ATT, EVENT, MSG>>) -> Self

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

Source

pub fn add_attributes_ref_mut( &mut self, attributes: Vec<Attribute<ATT, EVENT, MSG>>, )

add attributes using a mutable reference to self

Source

pub fn get_attributes(&self) -> Vec<Attribute<ATT, EVENT, MSG>>

get the attributes of this node

Source

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

returns the tag of this node if it is an element

Source

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

returns the text content if it is a text node

Source

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

returns the text if this node has only one child and is a text. includes: h1, h2..h6, p,

Source

pub fn get_children(&self) -> Option<&[Node<T, ATT, EVENT, MSG>]>

return the children of this node if it is an element

Trait Implementations§

Source§

impl<T: Clone, ATT, EVENT, MSG> Clone for Node<T, ATT, EVENT, MSG>
where MSG: 'static + Clone, EVENT: 'static + Clone, ATT: Clone + Clone,

Source§

fn clone(&self) -> Node<T, ATT, EVENT, 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<T: Debug, ATT, EVENT, MSG> Debug for Node<T, ATT, EVENT, MSG>
where MSG: 'static + Debug, EVENT: 'static + Debug, ATT: Clone + Debug,

Source§

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

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

impl<T, ATT, EVENT, MSG> Display for Node<T, ATT, EVENT, MSG>
where T: ToString, EVENT: 'static, MSG: 'static, ATT: PartialEq + Ord + ToString + Clone,

Source§

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

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

impl<T, ATT, EVENT, MSG> From<Element<T, ATT, EVENT, MSG>> for Node<T, ATT, EVENT, MSG>
where ATT: Clone,

Source§

fn from(v: Element<T, ATT, EVENT, MSG>) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq, ATT, EVENT, MSG> PartialEq for Node<T, ATT, EVENT, MSG>
where MSG: 'static + PartialEq, EVENT: 'static + PartialEq, ATT: Clone + PartialEq,

Source§

fn eq(&self, other: &Node<T, ATT, EVENT, 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<T, ATT, EVENT, MSG> StructuralPartialEq for Node<T, ATT, EVENT, MSG>
where MSG: 'static, EVENT: 'static, ATT: Clone,

Auto Trait Implementations§

§

impl<T, ATT, EVENT, MSG> Freeze for Node<T, ATT, EVENT, MSG>
where T: Freeze,

§

impl<T, ATT, EVENT, MSG> !RefUnwindSafe for Node<T, ATT, EVENT, MSG>

§

impl<T, ATT, EVENT, MSG> !Send for Node<T, ATT, EVENT, MSG>

§

impl<T, ATT, EVENT, MSG> !Sync for Node<T, ATT, EVENT, MSG>

§

impl<T, ATT, EVENT, MSG> Unpin for Node<T, ATT, EVENT, MSG>
where T: Unpin, ATT: Unpin,

§

impl<T, ATT, EVENT, MSG> !UnwindSafe for Node<T, ATT, EVENT, 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> 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,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.