rbx_tree is a common representation of the Roblox DOM for Rust. It's designed to play nicely with the borrow checker and allows accessing instances by ID in constant time.
Constructing a new tree of instances is accomplished by first creating an
RbxInstanceProperties
object that describes the root instance of the
tree, and then wrapping it with an RbxTree
:
use HashMap;
use ;
let props = RbxInstanceProperties ;
let mut tree = new;
println!;
Note that the maplit crate is incredibly useful for defining properties inline.
Once we have a tree, we can use RbxTree::insert_instance
and
RbxTree::get_instance
to add instances to the tree and retrieve them.
# use HashMap;
# use ;
use RbxValue;
use hashmap;
#
# let props = RbxInstanceProperties ;
#
# let mut tree = new;
#
let http_service = RbxInstanceProperties ;
let datamodel_id = tree.get_root_id;
let http_service_id = tree.insert_instance;
println!;
To change properties on an instance that's already present in the tree, use
RbxTree::get_instance_mut
. Note that it isn't possible to add or remove
children through this method, use RbxTree::insert_instance
instead.