pub struct Element<E: HtmlElement> { /* private fields */ }Expand description
A type-safe HTML element builder.
The type parameter E must implement [HtmlElement] and determines:
- The tag name (via
E::TAG) - Whether it’s a void element (via
E::VOID) - Which children are allowed (via
CanContain<Child>implementations)
Implementations§
Source§impl<E: HtmlElement> Element<E>
impl<E: HtmlElement> Element<E>
Sourcepub fn attr(
self,
name: impl Into<Cow<'static, str>>,
value: impl Into<String>,
) -> Self
pub fn attr( self, name: impl Into<Cow<'static, str>>, value: impl Into<String>, ) -> Self
Add an attribute with a string value.
Sourcepub fn attr_value<V: AttributeValue>(
self,
name: impl Into<Cow<'static, str>>,
value: V,
) -> Self
pub fn attr_value<V: AttributeValue>( self, name: impl Into<Cow<'static, str>>, value: V, ) -> Self
Add an attribute with a type-safe value.
Sourcepub fn bool_attr(self, name: impl Into<Cow<'static, str>>) -> Self
pub fn bool_attr(self, name: impl Into<Cow<'static, str>>) -> Self
Add a boolean attribute (no value, e.g., disabled, checked).
Sourcepub fn class(self, class: impl Into<String>) -> Self
pub fn class(self, class: impl Into<String>) -> Self
Add a class. Multiple calls append to the class list.
Sourcepub fn child<C, F>(self, f: F) -> Self
pub fn child<C, F>(self, f: F) -> Self
Add a child element.
The child type must be allowed by the parent’s content model.
This is enforced at compile time via the CanContain trait.
Sourcepub fn text(self, content: impl Into<String>) -> Selfwhere
E: CanContain<Text>,
pub fn text(self, content: impl Into<String>) -> Selfwhere
E: CanContain<Text>,
Add text content.
Only available for elements that can contain text (via CanContain<Text>).
Sourcepub fn raw(self, html: impl Into<String>) -> Selfwhere
E: CanContain<Text>,
pub fn raw(self, html: impl Into<String>) -> Selfwhere
E: CanContain<Text>,
Add raw HTML content (not escaped).
Use with caution - this bypasses XSS protection.
Sourcepub fn when<F>(self, condition: bool, f: F) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn when<F>(self, condition: bool, f: F) -> Selfwhere
F: FnOnce(Self) -> Self,
Conditionally add content.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for Element<E>
impl<E> RefUnwindSafe for Element<E>where
E: RefUnwindSafe,
impl<E> Send for Element<E>where
E: Send,
impl<E> Sync for Element<E>where
E: Sync,
impl<E> Unpin for Element<E>where
E: Unpin,
impl<E> UnwindSafe for Element<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more