pub fn insert_child(
        &mut self,
        mc: MutationContext<'gc, '_>,
        position: usize,
        mut child: XmlNode<'gc>,
    ) {
        let is_cyclic = self
            .ancestors()
            .any(|ancestor| GcCell::ptr_eq(ancestor.0, child.0));
        if is_cyclic {
            return;
        }

        match &mut *self.0.write(mc) {
            XmlNodeData::DocumentRoot { children, .. } | XmlNodeData::Element { children, .. } => {
                let old_parent = match *child.0.read() {
                    XmlNodeData::DocumentRoot { .. } => {
                        log::warn!("Cannot adopt other document roots");
                        return;
                    }
                    XmlNodeData::Element { parent, .. } | XmlNodeData::Text { parent, .. } => {
                        parent
                    }
                };

                if let Some(mut old_parent) = old_parent {
                    if !GcCell::ptr_eq(self.0, old_parent.0) {
                        old_parent.orphan_child(mc, child);
                    }
                }

                match &mut *child.0.write(mc) {
                    XmlNodeData::DocumentRoot { .. } => {
                        // This cannot happen as we quit before.
                        unreachable!();
                    }
                    XmlNodeData::Element { parent, .. } | XmlNodeData::Text { parent, .. } => {
                        *parent = Some(*self);
                    }
                }

                children.insert(position, child);

                let new_prev = position
                    .checked_sub(1)
                    .and_then(|p| children.get(p).cloned());
                let new_next = position
                    .checked_add(1)
                    .and_then(|p| children.get(p).cloned());
                child.adopt_siblings(mc, new_prev, new_next);
            }
            XmlNodeData::Text { .. } => {
                log::warn!("Text nodes cannot have children");
            }
        }
    }
/// Insert `child` into the children list of this node.
///
/// `child` will be adopted into the current tree: all child references
/// to other nodes or documents will be adjusted to reflect its new
/// position in the tree. This may remove it from any existing trees or
/// documents.
///
/// The `position` parameter is the position of the new child in
/// this node's children list. This is used to find and link the child's
/// siblings to each other.
Insert `child` into the children list of this node.
`child` will be adopted into the current tree: all child references
to other nodes or documents will be adjusted to reflect its new
position in the tree. This may remove it from any existing trees or
documents.

The `position` parameter is the position of the new child in
this node's children list. This is used to find and link the child's
siblings to each other.
Insert ` child ` into the children list of this node . ` child ` will be adopted into the current tree : all child references to other nodes or documents will be adjusted to reflect its new position in the tree . This may remove it from any existing trees or documents . The ` position ` parameter is the position of the new child in this node ' s children list . This is used to find and link the child ' s siblings to each other .
pub fn insert_child(
        &mut self,
        mc: MutationContext<'gc, '_>,
        position: usize,
        mut child: XmlNode<'gc>,
    ) {
        let is_cyclic = self
            .ancestors()
            .any(|ancestor| GcCell::ptr_eq(ancestor.0, child.0));
        if is_cyclic {
            return;
        }
        match &mut *self.0.write(mc) {
            XmlNodeData::DocumentRoot { children, .. } | XmlNodeData::Element { children, .. } => {
                let old_parent = match *child.0.read() {
                    XmlNodeData::DocumentRoot { .. } => {
                        log::warn!("Cannot adopt other document roots");
                        return;
                    }
                    XmlNodeData::Element { parent, .. } | XmlNodeData::Text { parent, .. } => {
                        parent
                    }
                };
                if let Some(mut old_parent) = old_parent {
                    if !GcCell::ptr_eq(self.0, old_parent.0) {
                        old_parent.orphan_child(mc, child);
                    }
                }
                match &mut *child.0.write(mc) {
                    XmlNodeData::DocumentRoot { .. } => {
                        // This cannot happen as we quit before.
                        unreachable!();
                    }
                    XmlNodeData::Element { parent, .. } | XmlNodeData::Text { parent, .. } => {
                        *parent = Some(*self);
                    }
                }
                children.insert(position, child);
                let new_prev = position
                    .checked_sub(1)
                    .and_then(|p| children.get(p).cloned());
                let new_next = position
                    .checked_add(1)
                    .and_then(|p| children.get(p).cloned());
                child.adopt_siblings(mc, new_prev, new_next);
            }
            XmlNodeData::Text { .. } => {
                log::warn!("Text nodes cannot have children");
            }
        }
    }
pub fn insert_child ( & mut self , mc : MutationContext < ' gc , ' _ > , position : usize , mut child : XmlNode < ' gc > , ) { let is_cyclic = self . ancestors ( ) . any ( | ancestor | GcCell :: ptr_eq ( ancestor . 0 , child . 0 ) ) ; if is_cyclic { return ; } match & mut * self . 0 . write ( mc ) { XmlNodeData :: DocumentRoot { children , .. } | XmlNodeData :: Element { children , .. } => { let old_parent = match * child . 0 . read ( ) { XmlNodeData :: DocumentRoot { .. } => { log :: warn ! ( " " ) ; return ; } XmlNodeData :: Element { parent , .. } | XmlNodeData :: Text { parent , .. } => { parent } } ; if let Some ( mut old_parent ) = old_parent { if ! GcCell :: ptr_eq ( self . 0 , old_parent . 0 ) { old_parent . orphan_child ( mc , child ) ; } } match & mut * child . 0 . write ( mc ) { XmlNodeData :: DocumentRoot { .. } => { // This cannot happen as we quit before. unreachable ! ( ) ; } XmlNodeData :: Element { parent , .. } | XmlNodeData :: Text { parent , .. } => { * parent = Some ( * self ) ; } } children . insert ( position , child ) ; let new_prev = position . checked_sub ( 1 ) . and_then ( | p | children . get ( p ) . cloned ( ) ) ; let new_next = position . checked_add ( 1 ) . and_then ( | p | children . get ( p ) . cloned ( ) ) ; child . adopt_siblings ( mc , new_prev , new_next ) ; } XmlNodeData :: Text { .. } => { log :: warn ! ( " " ) ; } } }
Insert `child` into the children list of this node.
Insert ` child ` into the children list of this node .
&mut self
mc
MutationContext<'gc, '_>
position
usize
child
XmlNode<'gc>