XElement

Struct XElement 

Source
pub struct XElement {
    pub key: XKey,
    pub tag_name: Option<XString>,
    pub value: XElementValue,
    pub before_render: Option<OnRenderCallback>,
    pub after_render: Option<OnRenderCallback>,
}
Expand description

Represents a generated HTML element.

Example: the HTML tag <input type="text" name="username" value="LamparoS@Pavy.one" /> would be written as

XElement {
    tag_name: Some("form".into()),
    key: XKey::default(),
    value: XElementValue::Static {
        attributes: vec![],
        children: vec![XNode::from(XElement {
            tag_name: Some("input".into()),
            key: XKey::default(),
            value: XElementValue::Static {
                attributes: vec![
                    XAttribute { name: "type".into(), value: "text".into() },
                    XAttribute { name: "name".into(), value: "username".into() },
                    XAttribute { name: "value".into(), value: "LamparoS@Pavy.one".into() },
                ],
                children: vec![],
                events: vec![],
            },
            before_render: None,
            after_render: None,
        })],
        events: vec![],
    },
    before_render: None,
    after_render: None,
}

Fields§

§key: XKey

The key of an element is used to reconcile a generated XElement with an existing Element node.

This allows reusing existing DOM nodes instead of generating entirely new ones when an XElement is recomputed after a signal is updated and triggers.

If the key is not set, a key is generated using the ordinal position of the node, and nodes are merged on a best-effort basis.

§tag_name: Option<XString>

The name of the HTML tag. Can be None when provided by a #[template(tag = ...)] attribute.

§value: XElementValue

The content of the HTML node.

§before_render: Option<OnRenderCallback>

A callback executed after the Element is created but before it is rendered.

On first render this will always be an empty node.

§after_render: Option<OnRenderCallback>

A callback executed after the Element is rendered.

Implementations§

Source§

impl XElement

Source

pub fn merge( &mut self, template: &XTemplate, old: &mut Self, element_rc: Ptr<Mutex<Element>>, )

Source

pub fn zero(&self) -> XElement

Trait Implementations§

Source§

impl Debug for XElement

Source§

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

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

impl From<XElement> for XNode

Source§

fn from(value: XElement) -> Self

Converts to this type from the input type.
Source§

impl IsTemplated for XElement

Source§

impl NamedType for XElement

Source§

fn type_name() -> &'static str

Auto Trait Implementations§

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, 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> UpdateAndReturn for T

Source§

type NewValue = T

Source§

fn and_return<R>( self, result: R, ) -> UpdateSignalResult<<T as UpdateAndReturn>::NewValue, R>