pub struct Handle { /* private fields */ }Expand description
A universal node handle. 16 bytes, Copy, Send, !Sync.
Internally: RawId (8 bytes) + DocumentCell (8 bytes).
All node types are newtypes around this.
See module-level doc for the thread-safety invariants.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn read_data<D: 'static, R: 'static>(
&self,
f: impl FnOnce(&D) -> R,
) -> Option<R>
pub fn read_data<D: 'static, R: 'static>( &self, f: impl FnOnce(&D) -> R, ) -> Option<R>
Read element-specific data through a scoped closure.
Sourcepub fn write_data<D: 'static, R: 'static>(
&self,
f: impl FnOnce(&mut D) -> R,
) -> Option<R>
pub fn write_data<D: 'static, R: 'static>( &self, f: impl FnOnce(&mut D) -> R, ) -> Option<R>
Write element-specific data. Marks dirty.
Sourcepub fn tag_name(&self) -> Option<&'static str>
pub fn tag_name(&self) -> Option<&'static str>
Tag name (e.g., “div”, “button”). None for non-element nodes.
Sourcepub fn class_name(&self) -> String
pub fn class_name(&self) -> String
Get the class attribute.
Sourcepub fn set_class_name(&self, class: impl Into<String>)
pub fn set_class_name(&self, class: impl Into<String>)
Set the class attribute.
Sourcepub fn attribute(&self, name: &str) -> Option<String>
pub fn attribute(&self, name: &str) -> Option<String>
Returns the attribute value for name, or None if absent.
Sourcepub fn set_attribute(&self, name: &str, value: impl Into<String>)
pub fn set_attribute(&self, name: &str, value: impl Into<String>)
Set an attribute.
Sourcepub fn remove_attribute(&self, name: &str) -> Option<String>
pub fn remove_attribute(&self, name: &str) -> Option<String>
Remove an attribute.
Sourcepub fn class_add(&self, name: &str)
pub fn class_add(&self, name: &str)
Add a CSS class. No-op if already present.
Chrome equivalent: element.classList.add("name").
Sourcepub fn class_remove(&self, name: &str)
pub fn class_remove(&self, name: &str)
Remove a CSS class. No-op if not present.
Chrome equivalent: element.classList.remove("name").
Sourcepub fn class_toggle(&self, name: &str) -> bool
pub fn class_toggle(&self, name: &str) -> bool
Toggle a CSS class. Returns true if now present.
Chrome equivalent: element.classList.toggle("name").
Sourcepub fn class_contains(&self, name: &str) -> bool
pub fn class_contains(&self, name: &str) -> bool
Check if an element has a CSS class.
Chrome equivalent: element.classList.contains("name").
Sourcepub fn append(&self, child: impl Into<Handle>) -> &Self
pub fn append(&self, child: impl Into<Handle>) -> &Self
Append child as the last child.
Accepts any node type (HtmlDivElement, Text, Handle, etc.).
Sourcepub fn child(self, child: impl Into<Handle>) -> Self
pub fn child(self, child: impl Into<Handle>) -> Self
Append a child and return self (Copy) for chaining.
doc.root()
.child(doc.div())
.child(doc.div());Sourcepub fn add_children<I, C>(self, items: I) -> Self
pub fn add_children<I, C>(self, items: I) -> Self
Append multiple children at once.
Sourcepub fn insert_before(&self, child: impl Into<Handle>)
pub fn insert_before(&self, child: impl Into<Handle>)
Insert child before this node.
Sourcepub fn first_child(&self) -> Option<Handle>
pub fn first_child(&self) -> Option<Handle>
First child.
Sourcepub fn last_child(&self) -> Option<Handle>
pub fn last_child(&self) -> Option<Handle>
Last child.
Sourcepub fn next_sibling(&self) -> Option<Handle>
pub fn next_sibling(&self) -> Option<Handle>
Next sibling.
Sourcepub fn prev_sibling(&self) -> Option<Handle>
pub fn prev_sibling(&self) -> Option<Handle>
Previous sibling.
pub fn node_kind(&self) -> Option<NodeType>
pub fn is_element(&self) -> bool
pub fn is_text(&self) -> bool
pub fn is_document(&self) -> bool
Sourcepub fn style(&self) -> StyleAccess
pub fn style(&self) -> StyleAccess
Per-property style access — like JavaScript’s element.style.
div.style().color(AbsoluteColor::RED);
div.style().display(Display::Flex);Sourcepub fn dispatch_event(&self, event: &dyn Event) -> bool
pub fn dispatch_event(&self, event: &dyn Event) -> bool
Dispatch an event to this node.
Runs the full capture -> target -> bubble pipeline.
Returns true if the default action was NOT prevented.
This mirrors EventTarget::dispatch_event() but works on raw Handle
without requiring the HasHandle trait (which would conflict with the
blanket From<T: HasHandle> impl). Used by EventHandler after hit
testing returns a node index resolved to a Handle.
Trait Implementations§
Source§impl<T: HasHandle> From<T> for Handle
Any type with HasHandle can convert to Handle.
Enables doc.root().append(btn) instead of doc.root().append(btn.handle()).
impl<T: HasHandle> From<T> for Handle
Any type with HasHandle can convert to Handle.
Enables doc.root().append(btn) instead of doc.root().append(btn.handle()).
impl Copy for Handle
impl Send for Handle
Auto Trait Implementations§
impl Freeze for Handle
impl !RefUnwindSafe for Handle
impl !Sync for Handle
impl Unpin for Handle
impl UnsafeUnpin for Handle
impl !UnwindSafe for Handle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more