1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
//! 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 std::collections::HashMap; //! use rbx_tree::{RbxInstanceProperties, RbxTree}; //! //! let props = RbxInstanceProperties { //! name: "My Cool Game".to_owned(), //! class_name: "DataModel".to_owned(), //! properties: HashMap::new(), //! }; //! //! let mut tree = RbxTree::new(props); //! println!("ID of instance we just inserted is {}", tree.get_root_id()); //! ``` //! //! 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 std::collections::HashMap; //! # use rbx_tree::{RbxInstanceProperties, RbxTree}; //! use rbx_tree::RbxValue; //! use maplit::hashmap; //! # //! # let props = RbxInstanceProperties { //! # name: "My Cool Game".to_owned(), //! # class_name: "DataModel".to_owned(), //! # properties: HashMap::new(), //! # }; //! # //! # let mut tree = RbxTree::new(props); //! # //! let http_service = RbxInstanceProperties { //! name: "HttpService".to_owned(), //! class_name: "HttpService".to_owned(), //! properties: hashmap! { // // Properties are represented via the RbxValue enum //! "HttpEnabled".to_owned() => RbxValue::Bool { //! value: true, //! }, //! }, //! }; //! //! let datamodel_id = tree.get_root_id(); //! let http_service_id = tree.insert_instance(http_service, datamodel_id); //! //! println!("HttpService has ID {}", http_service_id); //! ``` //! //! 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. //! //! [`RbxTree`]: struct.RbxTree.html //! [`RbxTree::insert_instance`]: struct.RbxTree.html#method.insert_instance //! [`RbxTree::get_instance`]: struct.RbxTree.html#method.get_instance //! [`RbxTree::get_instance_mut`]: struct.RbxTree.html#method.get_instance_mut //! [`RbxInstanceProperties`]: struct.RbxInstanceProperties.html //! [maplit]: https://crates.io/crates/maplit mod id; mod instance; mod tree; mod value; pub use crate::{ id::RbxId, instance::{RbxInstanceProperties, RbxInstance}, tree::{RbxTree, Descendants}, value::RbxValue, };