Skip to main content

DocumentMutator

Struct DocumentMutator 

Source
pub struct DocumentMutator<'doc> {
    pub doc: &'doc mut BaseDocument,
    /* private fields */
}

Fields§

§doc: &'doc mut BaseDocument

Document is public as an escape hatch, but users of this API should ideally avoid using it and prefer exposing additional functionality in DocumentMutator.

Implementations§

Source§

impl DocumentMutator<'_>

Source

pub fn new<'doc>(doc: &'doc mut BaseDocument) -> DocumentMutator<'doc>

Source

pub fn node_has_parent(&self, node_id: NodeId) -> bool

Source

pub fn previous_sibling_id(&self, node_id: NodeId) -> Option<NodeId>

Source

pub fn next_sibling_id(&self, node_id: NodeId) -> Option<NodeId>

Source

pub fn parent_id(&self, node_id: NodeId) -> Option<NodeId>

Source

pub fn last_child_id(&self, node_id: NodeId) -> Option<NodeId>

Source

pub fn child_ids(&self, node_id: NodeId) -> ThinVec<NodeId>

Source

pub fn element_name(&self, node_id: NodeId) -> Option<&QualName>

Source

pub fn node_at_path(&self, start_node_id: NodeId, path: &[u8]) -> NodeId

Source

pub fn create_comment_node(&mut self, contents: &str) -> NodeId

Source

pub fn create_text_node(&mut self, text: &str) -> NodeId

Source

pub fn create_document_fragment(&mut self) -> NodeId

A DocumentFragment: a parentless container that never appears in a box tree and whose children are what gets inserted when it is.

jQuery builds one during initialisation, so without this the library throws before it defines jQuery and every page depending on it loses its scripting. Eight sites in a hundred-site corpus failed that way, and they reported it as jQuery is not defined — the missing method itself says only not a callable function, which names nothing.

Source

pub fn create_html_document(&mut self, title: &str) -> NodeId

A detached HTML document: html > head > title, and body.

This backs document.implementation.createHTMLDocument, which jQuery calls during initialisation to decide whether it can parse markup through a second document. Reading createHTMLDocument off an absent implementation threw before jQuery had assigned itself to window, so every site depending on it reported jQuery is not defined – a global that was never missing.

The node lives in this document’s arena but is attached to nothing, so it never lays out or paints. That is what makes it cheap: no second BaseDocument, no second style engine, no second arena.

Source

pub fn create_document(&mut self, content_type: &'static str) -> NodeId

An empty, detached document in the existing arena.

Source

pub fn adopt_node(&mut self, node_id: NodeId, document_id: NodeId)

Use the native adoption path, including custom element reactions.

Source

pub fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, ) -> NodeId

Source

pub fn deep_clone_node(&mut self, node_id: NodeId) -> NodeId

Source

pub fn template_contents(&mut self, node_id: NodeId) -> NodeId

The independently owned contents fragment of an HTML template.

Source

pub fn set_node_text(&mut self, node_id: NodeId, value: &str)

Source

pub fn replace_character_data( &mut self, node_id: NodeId, offset: usize, count: usize, value: &str, ) -> Result<(), &'static str>

Replace CharacterData without resetting endpoints outside the replaced span.

Source

pub fn split_text( &mut self, node_id: NodeId, offset: usize, ) -> Result<NodeId, &'static str>

Source

pub fn append_text_to_node( &mut self, node_id: NodeId, text: &str, ) -> Result<(), AppendTextErr>

Source

pub fn add_attrs_if_missing(&mut self, node_id: NodeId, attrs: Vec<Attribute>)

Source

pub fn set_attribute(&mut self, node_id: NodeId, name: QualName, value: &str)

Source

pub fn clear_attribute(&mut self, node_id: NodeId, name: QualName)

Source

pub fn set_style_property(&mut self, node_id: NodeId, name: &str, value: &str)

Source

pub fn remove_style_property(&mut self, node_id: NodeId, name: &str)

Source

pub fn set_sub_document( &mut self, node_id: NodeId, sub_document: Box<dyn Document>, )

Source

pub fn remove_sub_document(&mut self, node_id: NodeId)

Source

pub fn remove_node(&mut self, node_id: NodeId)

Source

pub fn remove_and_drop_node(&mut self, node_id: NodeId) -> Option<Node>

Source

pub fn remove_and_drop_node_with( &mut self, node_id: NodeId, on_drop: &mut dyn FnMut(NodeId), ) -> Option<Node>

Like Self::remove_and_drop_node, but calls on_drop with the id of every dropped node (the node itself and all of its descendants).

Source

pub fn remove_and_drop_all_children(&mut self, node_id: NodeId)

Source

pub fn remove_node_if_unparented(&mut self, node_id: NodeId)

Source

pub fn remove_node_if_unparented_with( &mut self, node_id: NodeId, on_drop: &mut dyn FnMut(NodeId), )

Like Self::remove_node_if_unparented, but calls on_drop with the id of every dropped node (the node itself and all of its descendants).

Source

pub fn append_children(&mut self, parent_id: NodeId, child_ids: &[NodeId])

Remove all of the children from old_parent_id and append them to new_parent_id

Source

pub fn insert_nodes_before( &mut self, anchor_node_id: NodeId, new_node_ids: &[NodeId], )

Source

pub fn insert_nodes_after( &mut self, anchor_node_id: NodeId, new_node_ids: &[NodeId], )

Source

pub fn reparent_children( &mut self, old_parent_id: NodeId, new_parent_id: NodeId, )

Source

pub fn replace_node_with( &mut self, anchor_node_id: NodeId, new_node_ids: &[NodeId], )

Source§

impl<'doc> DocumentMutator<'doc>

Source

pub fn flush(&mut self)

Source

pub fn set_inner_html(&mut self, node_id: NodeId, html: &str)

Source

pub fn set_html_unsafe(&mut self, node_id: NodeId, html: &str)

Replace descendants and honor declarative shadow roots.

Trait Implementations§

Source§

impl Drop for DocumentMutator<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'doc> !RefUnwindSafe for DocumentMutator<'doc>

§

impl<'doc> !Send for DocumentMutator<'doc>

§

impl<'doc> !Sync for DocumentMutator<'doc>

§

impl<'doc> !UnwindSafe for DocumentMutator<'doc>

§

impl<'doc> Freeze for DocumentMutator<'doc>

§

impl<'doc> Unpin for DocumentMutator<'doc>

§

impl<'doc> UnsafeUnpin for DocumentMutator<'doc>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more