Skip to main content

Handle

Struct Handle 

Source
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

Source

pub fn raw(&self) -> RawId

The raw node ID (index + generation). Can be sent across threads.

Source

pub fn is_alive(&self) -> bool

Check if this node is still alive.

Source

pub fn read_data<D: 'static, R: 'static>( &self, f: impl FnOnce(&D) -> R, ) -> Option<R>

Read element-specific data through a scoped closure.

Source

pub fn write_data<D: 'static, R: 'static>( &self, f: impl FnOnce(&mut D) -> R, ) -> Option<R>

Write element-specific data. Marks dirty.

Source

pub fn tag_name(&self) -> Option<&'static str>

Tag name (e.g., “div”, “button”). None for non-element nodes.

Source

pub fn id(&self) -> String

Get the id attribute.

Source

pub fn set_id(&self, id: impl Into<String>)

Set the id attribute.

Source

pub fn class_name(&self) -> String

Get the class attribute.

Source

pub fn set_class_name(&self, class: impl Into<String>)

Set the class attribute.

Source

pub fn attribute(&self, name: &str) -> Option<String>

Returns the attribute value for name, or None if absent.

Source

pub fn set_attribute(&self, name: &str, value: impl Into<String>)

Set an attribute.

Source

pub fn remove_attribute(&self, name: &str) -> Option<String>

Remove an attribute.

Source

pub fn class_add(&self, name: &str)

Add a CSS class. No-op if already present. Chrome equivalent: element.classList.add("name").

Source

pub fn class_remove(&self, name: &str)

Remove a CSS class. No-op if not present. Chrome equivalent: element.classList.remove("name").

Source

pub fn class_toggle(&self, name: &str) -> bool

Toggle a CSS class. Returns true if now present. Chrome equivalent: element.classList.toggle("name").

Source

pub fn class_contains(&self, name: &str) -> bool

Check if an element has a CSS class. Chrome equivalent: element.classList.contains("name").

Source

pub fn append(&self, child: impl Into<Handle>) -> &Self

Append child as the last child.

Accepts any node type (HtmlDivElement, Text, Handle, etc.).

Source

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());
Source

pub fn add_children<I, C>(self, items: I) -> Self
where I: IntoIterator<Item = C>, C: Into<Handle>,

Append multiple children at once.

Source

pub fn insert_before(&self, child: impl Into<Handle>)

Insert child before this node.

Source

pub fn detach(&self)

Remove from parent.

Source

pub fn destroy(&self)

Destroy this node. All handles become stale.

Source

pub fn parent(&self) -> Option<Handle>

Parent node.

Source

pub fn first_child(&self) -> Option<Handle>

First child.

Source

pub fn last_child(&self) -> Option<Handle>

Last child.

Source

pub fn next_sibling(&self) -> Option<Handle>

Next sibling.

Source

pub fn prev_sibling(&self) -> Option<Handle>

Previous sibling.

Source

pub fn children(&self) -> Vec<Handle>

All children.

Source

pub fn node_kind(&self) -> Option<NodeType>

Source

pub fn is_element(&self) -> bool

Source

pub fn is_text(&self) -> bool

Source

pub fn is_document(&self) -> bool

Source

pub fn style(&self) -> StyleAccess

Per-property style access — like JavaScript’s element.style.

div.style().color(AbsoluteColor::RED);
div.style().display(Display::Flex);
Source

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 Clone for Handle

Source§

fn clone(&self) -> Handle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Handle

Source§

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

Formats the value using the given formatter. Read more
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()).

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl Copy for Handle

Source§

impl Send for Handle

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> ErasedDestructor for T
where T: 'static,