Struct rbx_dom_weak::WeakDom
source · pub struct WeakDom { /* private fields */ }
Expand description
Represents a DOM containing one or more Roblox instances.
Instances are described by Instance
objects and have a referent, a class
name, a name, properties, and an ordered list of children.
When constructing instances, you’ll want to create InstanceBuilder
objects and insert them into the tree.
Implementations§
source§impl WeakDom
impl WeakDom
sourcepub fn new(builder: InstanceBuilder) -> WeakDom
pub fn new(builder: InstanceBuilder) -> WeakDom
Construct a new WeakDom
described by the given InstanceBuilder
.
sourcepub fn into_raw(self) -> (Ref, HashMap<Ref, Instance>)
pub fn into_raw(self) -> (Ref, HashMap<Ref, Instance>)
Consumes the WeakDom, returning its underlying root ref and backing storage. This method is useful when tree-preserving operations are too slow.
sourcepub fn root_mut(&mut self) -> &mut Instance
pub fn root_mut(&mut self) -> &mut Instance
Returns a mutable reference to the root instance of the WeakDom
.
sourcepub fn get_by_ref(&self, referent: Ref) -> Option<&Instance>
pub fn get_by_ref(&self, referent: Ref) -> Option<&Instance>
Returns a reference to an instance by referent, or None
if it is not
found.
sourcepub fn get_by_ref_mut(&mut self, referent: Ref) -> Option<&mut Instance>
pub fn get_by_ref_mut(&mut self, referent: Ref) -> Option<&mut Instance>
Returns a mutable reference to an instance by referent, or None
if
it is not found.
sourcepub fn insert(&mut self, parent_ref: Ref, root_builder: InstanceBuilder) -> Ref
pub fn insert(&mut self, parent_ref: Ref, root_builder: InstanceBuilder) -> Ref
Insert a new instance into the DOM with the given parent. The parent is allowed to be the none Ref.
Panics
Panics if parent_ref
is some and does not refer to an instance in the DOM.
sourcepub fn destroy(&mut self, referent: Ref)
pub fn destroy(&mut self, referent: Ref)
Destroy the instance with the given referent.
Panics
Panics if referent
does not refer to an instance in the DOM.
Will also panic if referent
refers to the root instance in this
WeakDom
.
sourcepub fn transfer(
&mut self,
referent: Ref,
dest: &mut WeakDom,
dest_parent_ref: Ref
)
pub fn transfer( &mut self, referent: Ref, dest: &mut WeakDom, dest_parent_ref: Ref )
Move the instance with the given referent to a new WeakDom
, parenting
it to the given ref. To move to within the same DOM, use
WeakDom::transfer_within
.
This function would be called move
, but that’s a Rust keyword!
Panics
Panics if referent
does not refer to an instance in self
or if
dest_parent_ref
does not refer to an instance in other_dom
.
Will also panic if referent
refers to the root instance in this
WeakDom
.
sourcepub fn transfer_within(&mut self, referent: Ref, dest_parent_ref: Ref)
pub fn transfer_within(&mut self, referent: Ref, dest_parent_ref: Ref)
Move the instance with the given referent to a new parent within the
same WeakDom
. To move to another DOM, use WeakDom::transfer
.
This function would be called move_within
, but move
is a Rust
keyword and consistency with transfer
is valuable.
Panics
Panics if referent
or dest_parent_ref
do not refer to instances in
self
.
Will also panic if referent
refers to the root instance in this
WeakDom
.
sourcepub fn clone_within(&mut self, referent: Ref) -> Ref
pub fn clone_within(&mut self, referent: Ref) -> Ref
Clone the instance with the given referent
and all its descendants
(i.e. the entire subtree) into the same WeakDom.
After the operation, the root of the cloned subtree has no parent.
Any Ref properties that point to instances contained in the subtree are rewritten to point to the cloned instances.
sourcepub fn clone_into_external(&self, referent: Ref, dest: &mut WeakDom) -> Ref
pub fn clone_into_external(&self, referent: Ref, dest: &mut WeakDom) -> Ref
Clone the instance with the given referent
and all its descendants (i.e. the
entire subtree) into the given WeakDom.
After the operation, the root of the cloned subtree has no parent.
Any Ref properties that point to instances contained in the subtree are
rewritten to point to the cloned instances. Any other Ref properties
would be invalid in dest
and are thus rewritten to be Ref::none()
This means that if you call this method on multiple different instances, Ref
properties will not necessarily be preserved in the destination dom. If you’re
cloning multiple instances, prefer clone_multiple_into_external
instead!