pub struct Element { /* private fields */ }Expand description
Represents an HTML element with its tag name, attributes, and children.
Elements are the building blocks of the RSX tree structure. Each element can have attributes (like class, id, etc.) and can contain other elements or text nodes as children.
You typically won’t create Elements directly, but rather use the rsx! macro:
use simple_rsx::*;
let element = rsx!(
<div class="container">
<p>Hello world!</p>
</div>
);Implementations§
Source§impl Element
impl Element
Sourcepub fn new(tag: &str) -> Node
pub fn new(tag: &str) -> Node
Creates a new Element node with the specified tag name.
§Example
use simple_rsx::*;
let element = Element::new("div");
assert!(matches!(element, Node::Element(_)));Sourcepub fn set_attribute(&mut self, name: &str, value: impl Attribute)
pub fn set_attribute(&mut self, name: &str, value: impl Attribute)
Sets an attribute on the element.
§Example
use simple_rsx::*;
let mut node = Element::new("div");
let mut element = node.as_element_mut().unwrap();
element.set_attribute("class", "container");Sourcepub fn append_child(&mut self, node: Node)
pub fn append_child(&mut self, node: Node)
Adds a child node to this element.
§Example
use simple_rsx::*;
let mut parent_node = Element::new("div");
let mut parent = parent_node.as_element_mut().unwrap();
parent.append_child(Element::new("p"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Element
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnwindSafe for Element
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