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>
impl<'a, Ext> NodeMut<'a, Ext>
pub fn id(&self) -> NodeId
pub fn as_ref(&self) -> NodeRef<'_, Ext>
Sourcepub fn dom_mut(&mut self) -> &mut Dom<Ext>
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.
Sourcepub fn into_dom_mut(self) -> &'a mut Dom<Ext>
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§impl<'a, Ext: 'static> NodeMut<'a, Ext>
impl<'a, Ext: 'static> NodeMut<'a, Ext>
pub fn set_attribute(&mut self, key: &str, value: &str) -> Result<()>
pub fn remove_attribute(&mut self, key: &str) -> Result<bool>
pub fn toggle_attribute(&mut self, key: &str) -> Result<bool>
pub fn set_id(&mut self, value: &str) -> Result<()>
pub fn add_class(&mut self, class: &str) -> Result<()>
pub fn remove_class(&mut self, class: &str) -> Result<bool>
pub fn toggle_class(&mut self, class: &str) -> Result<bool>
pub fn replace_class(&mut self, old: &str, new: &str) -> Result<bool>
Sourcepub fn set_class_name(&mut self, value: &str) -> Result<()>
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.
Sourcepub fn class_list_mut(&mut self) -> DomTokenListMut<'_, Ext>
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.
Sourcepub fn dataset_mut(&mut self) -> DomStringMapMut<'_, Ext>
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.
Sourcepub fn set_tab_index(&mut self, value: i32) -> Result<()>
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.
DOM HTMLElement.hidden setter. true writes the boolean
attribute (empty value); false removes it.
Sourcepub fn set_content_editable(&mut self, value: &str) -> Result<()>
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.
Sourcepub fn toggle_attribute_force(
&mut self,
name: &str,
force: Option<bool>,
) -> Result<bool>
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); returnstrue.force = Some(false)→ ensure absent; returnsfalse.force = None→ flip; returns the post-flip presence.
pub fn append_child(&mut self, child: NodeId) -> Result<()>
pub fn prepend_child(&mut self, child: NodeId) -> Result<()>
pub fn remove_child(&mut self, child: NodeId) -> Result<()>
pub fn replace_child(&mut self, old: NodeId, new: NodeId) -> Result<()>
pub fn insert_before( &mut self, new: NodeId, reference: Option<NodeId>, ) -> Result<()>
pub fn insert_adjacent( &mut self, position: AdjacentPosition, new: NodeId, ) -> Result<()>
pub fn clear_children(&mut self) -> Result<()>
Sourcepub fn append(
&mut self,
children: impl IntoIterator<Item = NodeOrString>,
) -> Result<()>
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.
Sourcepub fn prepend(
&mut self,
children: impl IntoIterator<Item = NodeOrString>,
) -> Result<()>
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.
Sourcepub fn before(
&mut self,
siblings: impl IntoIterator<Item = NodeOrString>,
) -> Result<()>
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.
Sourcepub fn after(
&mut self,
siblings: impl IntoIterator<Item = NodeOrString>,
) -> Result<()>
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).
Sourcepub fn replace_children(
&mut self,
children: impl IntoIterator<Item = NodeOrString>,
) -> Result<()>
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.
Sourcepub fn replace_with(
self,
siblings: impl IntoIterator<Item = NodeOrString>,
) -> Result<()>
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 consumedSourcepub fn remove_self(self) -> Result<()>
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 consumedSourcepub fn set_node_value(&mut self, data: &str) -> Result<()>
pub fn set_node_value(&mut self, data: &str) -> Result<()>
Set Text/Comment node’s own data. Errors on Element/Fragment.
Fires Mutation::CharacterDataChanged.
Sourcepub fn set_data(&mut self, data: &str) -> Result<()>
pub fn set_data(&mut self, data: &str) -> Result<()>
CharacterData.data setter — alias for set_node_value on Text/
Comment.
Sourcepub fn edit_text(
&mut self,
start: usize,
end: usize,
replacement: &str,
) -> Result<()>
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—startorendovershoot the data length or land mid-UTF-8-codepoint. Editors that derive offsets fromPosition/ grapheme walks won’t hit this.
Fires Mutation::CharacterDataChanged (via set_node_value).