Skip to main content

NodeMut

Struct NodeMut 

Source
pub struct NodeMut<'a, Ext: 'static = ()> { /* private fields */ }
Expand description

Mutable handle. All mutations go through this wrapper so future index maintenance hooks (Phase 4) have a single chokepoint.

Implementations§

Source§

impl<'a, Ext> NodeMut<'a, Ext>

Source

pub fn id(&self) -> NodeId

Source

pub fn as_ref(&self) -> NodeRef<'_, Ext>

Source

pub fn dom_mut(&mut self) -> &mut Dom<Ext>

Reborrow the inner &mut Dom<Ext>. Lets downstream crates (notably rdom-parser’s NodeMutHtml extension trait) reach Dom-level operations that aren’t surfaced on NodeMut directly. The borrow shares the receiver’s lifetime.

Source

pub fn into_dom_mut(self) -> &'a mut Dom<Ext>

Consume this NodeMut and return the inner &'a mut Dom<Ext>. Used by extension traits whose methods need to operate on the Dom past the receiver’s logical lifetime (e.g. set_outer_html, which destroys the receiver).

Source

pub fn ext_mut(&mut self) -> Option<&mut Ext>

Mutable borrow of the per-element extension data. None for Text / Comment / Fragment. Pair of NodeRef::ext().

Source§

impl<'a, Ext: 'static> NodeMut<'a, Ext>

Source

pub fn set_attribute(&mut self, key: &str, value: &str) -> Result<()>

Source

pub fn remove_attribute(&mut self, key: &str) -> Result<bool>

Source

pub fn toggle_attribute(&mut self, key: &str) -> Result<bool>

Source

pub fn set_id(&mut self, value: &str) -> Result<()>

Source

pub fn add_class(&mut self, class: &str) -> Result<()>

Source

pub fn remove_class(&mut self, class: &str) -> Result<bool>

Source

pub fn toggle_class(&mut self, class: &str) -> Result<bool>

Source

pub fn replace_class(&mut self, old: &str, new: &str) -> Result<bool>

Source

pub fn set_class_name(&mut self, value: &str) -> Result<()>

Replace the entire class attribute. DOM Element.className setter.

Writes the raw attribute string AND rebuilds the canonical classList from whitespace-separated tokens — both reads (NodeRef::class_name and NodeRef::class_list) reflect the new value after this call. Empty value clears the classList entirely.

Source

pub fn class_list_mut(&mut self) -> DomTokenListMut<'_, Ext>

Mutating handle for the element’s class tokens. DOM Element.classList.

The returned wrapper holds a reborrowed NodeMut; drop the wrapper to release the borrow before mutating other fields on this element.

Source

pub fn dataset_mut(&mut self) -> DomStringMapMut<'_, Ext>

DOM HTMLElement.dataset mutator — write-side handle for data-* attributes keyed by their camelCase form. The returned wrapper holds a reborrowed NodeMut; drop it before mutating other fields on this element.

Source

pub fn set_tab_index(&mut self, value: i32) -> Result<()>

DOM HTMLElement.tabIndex setter. Writes the integer value to the tabindex attribute as its decimal string form.

Source

pub fn set_hidden(&mut self, value: bool) -> Result<()>

DOM HTMLElement.hidden setter. true writes the boolean attribute (empty value); false removes it.

Source

pub fn set_content_editable(&mut self, value: &str) -> Result<()>

DOM HTMLElement.contentEditable setter (HTML §6.8.1), matched ASCII case-insensitively: "inherit" removes the attribute; "true", "false" and "plaintext-only" write that keyword in lowercase; anything else is a DomError::Syntax and leaves the attribute untouched.

Source

pub fn toggle_attribute_force( &mut self, name: &str, force: Option<bool>, ) -> Result<bool>

Toggle an attribute with optional force. DOM Element.toggleAttribute(qualifiedName, force?).

  • force = Some(true) → ensure present (empty string value if newly added); returns true.
  • force = Some(false) → ensure absent; returns false.
  • force = None → flip; returns the post-flip presence.
Source

pub fn append_child(&mut self, child: NodeId) -> Result<()>

Source

pub fn prepend_child(&mut self, child: NodeId) -> Result<()>

Source

pub fn remove_child(&mut self, child: NodeId) -> Result<()>

Source

pub fn replace_child(&mut self, old: NodeId, new: NodeId) -> Result<()>

Source

pub fn insert_before( &mut self, new: NodeId, reference: Option<NodeId>, ) -> Result<()>

Source

pub fn insert_adjacent( &mut self, position: AdjacentPosition, new: NodeId, ) -> Result<()>

Source

pub fn clear_children(&mut self) -> Result<()>

Source

pub fn append( &mut self, children: impl IntoIterator<Item = NodeOrString>, ) -> Result<()>

Append each item to the end of this node’s child list, in order. Text items create fresh text nodes. DOM ParentNode.append.

Source

pub fn prepend( &mut self, children: impl IntoIterator<Item = NodeOrString>, ) -> Result<()>

Insert each item at the start of this node’s child list, in order — the first item of children becomes the new first child. DOM ParentNode.prepend.

Source

pub fn before( &mut self, siblings: impl IntoIterator<Item = NodeOrString>, ) -> Result<()>

Insert each item as a sibling immediately before this node, in order. DOM ChildNode.before.

Silently no-ops when this node has no parent (browser- faithful). Text items create fresh text nodes only when insertion actually happens.

Source

pub fn after( &mut self, siblings: impl IntoIterator<Item = NodeOrString>, ) -> Result<()>

Insert each item as a sibling immediately after this node, in order. DOM ChildNode.after.

Silently no-ops when this node has no parent (browser- faithful).

Source

pub fn replace_children( &mut self, children: impl IntoIterator<Item = NodeOrString>, ) -> Result<()>

Clear this node’s children and append the new ones. DOM ParentNode.replaceChildren.

Source

pub fn replace_with( self, siblings: impl IntoIterator<Item = NodeOrString>, ) -> Result<()>

Replace this node with siblings, inserted at its position in the parent, then detach this node. DOM ChildNode.replaceWith.

Consumes self — the receiver is detached from the tree, so the handle is no longer usable. Silently no-ops when this node has no parent.

ⓘ
use rdom_core::Dom;
let mut dom: Dom = Dom::new();
let parent = dom.create_element("div");
let el = dom.create_element("span");
dom.append_child(parent, el).unwrap();
let nm = dom.node_mut(el);
nm.replace_with([]).unwrap();
let _ = nm.id();  // ERROR: nm was consumed
Source

pub fn remove_self(self) -> Result<()>

Detach this node from its parent. DOM ChildNode.remove.

Consumes self. Silently no-ops on parentless nodes. The node remains in the arena — it’s just orphaned.

ⓘ
use rdom_core::Dom;
let mut dom: Dom = Dom::new();
let parent = dom.create_element("div");
let el = dom.create_element("span");
dom.append_child(parent, el).unwrap();
let nm = dom.node_mut(el);
nm.remove_self().unwrap();
let _ = nm.id();  // ERROR: nm was consumed
Source

pub fn set_node_value(&mut self, data: &str) -> Result<()>

Set Text/Comment node’s own data. Errors on Element/Fragment. Fires Mutation::CharacterDataChanged.

Source

pub fn set_data(&mut self, data: &str) -> Result<()>

CharacterData.data setter — alias for set_node_value on Text/ Comment.

Source

pub fn edit_text( &mut self, start: usize, end: usize, replacement: &str, ) -> Result<()>

Replace the byte range [start..end) of a Text/Comment node’s data with replacement. Convenience over set_node_value for editors that want byte-precise mutations (insert, delete, replace a range) without assembling the full new string.

Errors:

  • WrongNodeType — node isn’t Text/Comment.
  • InvalidOffset — start or end overshoot the data length or land mid-UTF-8-codepoint. Editors that derive offsets from Position / grapheme walks won’t hit this.

Fires Mutation::CharacterDataChanged (via set_node_value).

Source§

impl<'a, Ext: Default> NodeMut<'a, Ext>

Source

pub fn set_text_content(&mut self, text: &str) -> Result<()>

textContent setter — replace all children of this Element/Fragment with a single Text node. Errors on Text/Comment (use set_data).

Auto Trait Implementations§

§

impl<'a, Ext = ()> !RefUnwindSafe for NodeMut<'a, Ext>

§

impl<'a, Ext = ()> !Send for NodeMut<'a, Ext>

§

impl<'a, Ext = ()> !Sync for NodeMut<'a, Ext>

§

impl<'a, Ext = ()> !UnwindSafe for NodeMut<'a, Ext>

§

impl<'a, Ext> Freeze for NodeMut<'a, Ext>
where &'a mut Dom<Ext>: Freeze,

§

impl<'a, Ext> Unpin for NodeMut<'a, Ext>
where &'a mut Dom<Ext>: Unpin,

§

impl<'a, Ext> UnsafeUnpin for NodeMut<'a, Ext>
where &'a mut Dom<Ext>: UnsafeUnpin,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.