Struct sauron::Element

source ·
pub struct Element<MSG> {
    pub namespace: Option<&'static str>,
    pub tag: &'static str,
    pub self_closing: bool,
    /* private fields */
}
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<&'static str>

namespace of this element, svg elements requires namespace to render correcly in the browser

§tag: &'static str

the element tag, such as div, a, button

§self_closing: bool

is the element has a self closing tag

Implementations§

source§

impl<MSG> Element<MSG>

source

pub fn new( namespace: Option<&'static str>, tag: &'static str, attrs: impl IntoIterator<Item = Attribute<MSG>>, children: impl IntoIterator<Item = Node<MSG>>, self_closing: bool ) -> Element<MSG>

create a new instance of an element

source

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

add attributes to this element

source

pub fn add_children(&mut self, children: impl IntoIterator<Item = Node<MSG>>)

add children virtual node to this element

source

pub fn children(&self) -> &[Node<MSG>]

returns a refernce to the children of this node

source

pub fn children_mut(&mut self) -> &mut [Node<MSG>]

returns a mutable reference to the children of this 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 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<MSG>>

consume self and return the children

source

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

return a reference to the attribute of this element

source

pub fn take_attributes(self) -> Vec<Attribute<MSG>>

consume self and return the attributes

source

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

return the namespace of this element

source

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

return the tag of this element

source

pub fn take_tag(self) -> &'static str

consume self and return the tag of this element

source

pub fn set_tag(&mut self, tag: &'static str)

change the tag of this element

source

pub fn remove_attribute(&mut self, name: &&'static str)

remove the attributes with this key

source

pub fn set_attributes( &mut self, attrs: impl IntoIterator<Item = Attribute<MSG>> )

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

merge to existing attributes if it exist

source

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

return all the attribute values which the name &AttributeName

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 element

source

pub fn group_indexed_attributes_per_name<'a>( attrs: &'a [Attribute<MSG>] ) -> IndexMap<&'a &'static str, Vec<(usize, &'a Attribute<MSG>)>>

grouped the attributes, but retain the index of the attribute relative to its location in the element

source

pub fn has_mount_callback(&self) -> bool

return true if this element has a mount callback

source§

impl<MSG> Element<MSG>

source

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

map the msg of this element such that Element<MSG> becomes Element<MSG2>

source§

impl<MSG> Element<MSG>

source

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

render element nodes

Trait Implementations§

source§

impl<MSG> Clone for Element<MSG>

source§

fn clone(&self) -> Element<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 Element<MSG>

source§

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

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

impl<MSG> PartialEq for Element<MSG>

source§

fn eq(&self, __other: &Element<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 Element<MSG>

Auto Trait Implementations§

§

impl<MSG> Freeze for Element<MSG>

§

impl<MSG> !RefUnwindSafe for Element<MSG>

§

impl<MSG> !Send for Element<MSG>

§

impl<MSG> !Sync for Element<MSG>

§

impl<MSG> Unpin for Element<MSG>

§

impl<MSG> !UnwindSafe for Element<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.