#roblox #dom #weak

rbx_dom_weak

Weakly-typed Roblox DOM implementation for Rust

18 stable releases

2.4.0 Jun 5, 2022
2.3.0 Oct 11, 2021
2.2.0 Jul 19, 2021
2.0.0-alpha.1 Feb 16, 2021
0.3.1 Feb 26, 2019

#130 in Games

Download history 277/week @ 2022-08-13 269/week @ 2022-08-20 174/week @ 2022-08-27 235/week @ 2022-09-03 675/week @ 2022-09-10 203/week @ 2022-09-17 133/week @ 2022-09-24 253/week @ 2022-10-01 176/week @ 2022-10-08 178/week @ 2022-10-15 100/week @ 2022-10-22 113/week @ 2022-10-29 166/week @ 2022-11-05 159/week @ 2022-11-12 106/week @ 2022-11-19 41/week @ 2022-11-26

502 downloads per month
Used in 5 crates

MIT license

125KB
3K SLoC

rbx_dom_weak

rbx_dom_weak on crates.io rbx_dom_weak docs

More details about this crate are available on the rbx-dom GitHub.

Weakly-typed implementation of Roblox's DOM, used for representing instances in external tools.

Coverage

Because rbx_dom_weak is weakly-typed, it doesn't need to be updated when new instances are added to Roblox. It does, however, have to be updated when new datatypes like Vector3int16 are added.


lib.rs:

rbx_dom_weak 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 [InstanceBuilder] object that describes a tree of instances and then wrapping it with an [WeakDom]:

use rbx_dom_weak::{InstanceBuilder, WeakDom};

let dm = InstanceBuilder::new("DataModel");

let mut dom = WeakDom::new(dm);

println!("ID of DOM root is {:?}", dom.root_ref());

Once we have a tree, we can use [WeakDom::insert] and [WeakDom::get_by_ref] to add instances to the tree and retrieve them.

use rbx_dom_weak::{InstanceBuilder, WeakDom};

let mut dom = WeakDom::new(InstanceBuilder::new("DataModel"));

// We can define properties using any type that can be converted to an
// rbx_dom_weak::types::Variant.
let http_service = InstanceBuilder::new("HttpService")
    .with_property("HttpEnabled", true);

let http_service_id = dom.insert(dom.root_ref(), http_service);

println!("HttpService has ID {:?}", http_service_id);

To change properties on an instance that's already present in the tree, use [WeakDom::get_by_ref_mut]. Note that it isn't possible to add or remove children through this method, use [WeakDom::insert] and [WeakDom::destroy] instead.

Dependencies

~2.1–3MB
~68K SLoC