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

source

pub fn new(builder: InstanceBuilder) -> WeakDom

Construct a new WeakDom described by the given InstanceBuilder.

source

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.

source

pub fn root_ref(&self) -> Ref

Returns the referent of the root instance of the WeakDom.

source

pub fn root(&self) -> &Instance

Returns a reference to the root instance of the WeakDom.

source

pub fn root_mut(&mut self) -> &mut Instance

Returns a mutable reference to the root instance of the WeakDom.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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!

source

pub fn clone_multiple_into_external( &self, referents: &[Ref], dest: &mut WeakDom ) -> Vec<Ref>

Similar to clone_into_external, but clones multiple subtrees all at once. This method will preserve Ref properties that point across the cloned subtrees.

Trait Implementations§

source§

impl Debug for WeakDom

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for WeakDom

source§

fn default() -> WeakDom

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V