Skip to main content

Element

Struct Element 

Source
pub struct Element {
    pub tag: &'static str,
    pub class: Option<String>,
    pub attrs: HashMap<&'static str, String>,
    pub text: Option<String>,
    pub children: Vec<Element>,
    pub handlers: Vec<EventHandler>,
}
Expand description

The fundamental UI node. Every tag in a view! block becomes one of these.

Fields§

§tag: &'static str

Tag name: “h1”, “button”, “p”, “img”, “input”, “div”, etc.

§class: Option<String>

CSS class string, e.g. "title" or "btn primary-btn".

§attrs: HashMap<&'static str, String>

Arbitrary HTML-like attributes (src, alt, placeholder, …).

§text: Option<String>

Text content for leaf nodes.

§children: Vec<Element>

Child elements.

§handlers: Vec<EventHandler>

Registered event handlers.

Implementations§

Source§

impl Element

Source

pub fn new(tag: &'static str) -> Self

Create a new element with the given tag.

Source

pub fn class(self, cls: impl Into<String>) -> Self

Set the class attribute.

Source

pub fn attr(self, key: &'static str, value: impl Into<String>) -> Self

Set a generic attribute.

Source

pub fn text(self, content: impl Into<String>) -> Self

Set text content.

Source

pub fn child(self, child: Element) -> Self

Add a child element.

Source

pub fn on(self, handler: EventHandler) -> Self

Attach an event handler.

Source

pub fn h1() -> Self

<h1>

Source

pub fn h2() -> Self

<h2>

Source

pub fn h3() -> Self

<h3>

Source

pub fn p() -> Self

<p>

Source

pub fn button() -> Self

<button>

Source

pub fn img() -> Self

<img>

Source

pub fn input() -> Self

<input>

Source

pub fn div() -> Self

<div>

Source

pub fn span() -> Self

<span>

Source

pub fn a() -> Self

<a>

Source

pub fn debug_render(&self, indent: usize) -> String

Render this element tree as a human-readable string (for debugging).

Trait Implementations§

Source§

impl Debug for Element

Source§

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

Formats the value using the given formatter. Read more

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.