Crate rbx_dom_weak

Source
Expand description

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.

Re-exports§

pub use rbx_types as types;

Structs§

AHashMap
A HashMap using RandomState to hash the items. (Requires the std feature to be enabled.)
DomViewer
Contains state for viewing and redacting nondeterministic portions of WeakDom objects, making them suitable for usage in snapshot tests.
Instance
An instance contained inside of a WeakDom.
InstanceBuilder
Represents an instance that can be turned into a new WeakDom, or inserted into an existing one.
Ustr
A handle representing a string in the global string cache.
ViewedInstance
A transformed view into a WeakDom or Instance that has been redacted and transformed to be more readable.
WeakDom
Represents a DOM containing one or more Roblox instances.

Traits§

HashMapExt
Helper trait that provides convenience methods for AHashMap and UstrMap.

Functions§

ustr
Create a new Ustr from the given str.

Type Aliases§

UstrMap
A standard HashMap using Ustr as the key type with a custom Hasher that just uses the precomputed hash for speed instead of calculating it.
UstrSet
A standard HashSet using Ustr as the key type with a custom Hasher that just uses the precomputed hash for speed instead of calculating it.