pub trait NodeMutHtml<'a, Ext>where
Ext: Default + 'static,{
// Required methods
fn set_inner_html(&mut self, html: &str) -> Result<()>;
fn set_outer_html(self, html: &str) -> Result<NodeId>;
fn insert_adjacent_html(
&mut self,
position: AdjacentPosition,
html: &str,
) -> Result<()>;
}Expand description
HTML setters on NodeMut. Brings the innerHTML /
outerHTML / insertAdjacentHTML ergonomics that rdom-core
can’t expose directly (since it can’t depend on the parser).
Implemented for any NodeMut<'_, Ext> whose Ext is
Default + 'static (the parser’s bound for materializing new
elements).
Required Methods§
Sourcefn set_inner_html(&mut self, html: &str) -> Result<()>
fn set_inner_html(&mut self, html: &str) -> Result<()>
Parse html and use it as the receiver’s children,
replacing whatever was there. DOM Element.innerHTML
setter.
The existing subtree is dropped — arena slots are freed and listeners (including AbortSignal-controlled ones) are released.
Errors: any ParseError from the underlying parser.
Sourcefn set_outer_html(self, html: &str) -> Result<NodeId>
fn set_outer_html(self, html: &str) -> Result<NodeId>
Replace the receiver in its parent with the parsed top-
level nodes from html. DOM Element.outerHTML setter.
Consumes self — the receiver is detached and dropped,
so the handle is no longer usable.
Returns the NodeId of the first new top-level node;
remaining top-level nodes are spliced in at the same
position.
Errors:
ParseErrorfrom the underlying parser.ParseError(synthesized) if the receiver has no parent — outer-HTML replacement requires an attached element.ParseError(synthesized) if the parsed fragment is empty.
use rdom_core::Dom;
use rdom_parser::NodeMutHtml;
let mut dom: Dom = Dom::new();
let root = dom.root();
let el = dom.create_element("div");
dom.append_child(root, el).unwrap();
let nm = dom.node_mut(el);
nm.set_outer_html("<p>x</p>").unwrap();
let _ = nm.id(); // ERROR: nm was consumedSourcefn insert_adjacent_html(
&mut self,
position: AdjacentPosition,
html: &str,
) -> Result<()>
fn insert_adjacent_html( &mut self, position: AdjacentPosition, html: &str, ) -> Result<()>
Parse html and insert the resulting nodes at position
relative to the receiver. DOM
Element.insertAdjacentHTML(position, html).
BeforeBegin and AfterEnd require a parent — both fail
with a synthesized ParseError if the receiver is
parentless. AfterBegin and BeforeEnd always succeed
when the parse succeeds.
Errors: any ParseError from the underlying parser,
plus a synthesized one for the parent-required positions.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".