diff --git a/rbx_dom_weak/src/instance.rs b/rbx_dom_weak/src/instance.rs index 3a1cfad4f..9b225f77c 100644 --- a/rbx_dom_weak/src/instance.rs +++ b/rbx_dom_weak/src/instance.rs @@ -1,6 +1,8 @@ use rbx_types::{Ref, Variant}; use ustr::{Ustr, UstrMap}; +use crate::UstrMapExt; + /** Represents an instance that can be turned into a new [`WeakDom`][crate::WeakDom], or inserted into an existing one. @@ -50,7 +52,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: UstrMap::default(), + properties: UstrMap::new(), children: Vec::new(), } } @@ -61,7 +63,7 @@ impl InstanceBuilder { referent: Ref::new(), name: String::new(), class: Ustr::default(), - properties: UstrMap::default(), + properties: UstrMap::new(), children: Vec::new(), } } diff --git a/rbx_dom_weak/src/lib.rs b/rbx_dom_weak/src/lib.rs index 55d8c87a4..8c261b864 100644 --- a/rbx_dom_weak/src/lib.rs +++ b/rbx_dom_weak/src/lib.rs @@ -54,3 +54,23 @@ pub use crate::{ instance::{Instance, InstanceBuilder}, viewer::{DomViewer, ViewedInstance}, }; + +/// Helper trait that provides convenience methods for `UstrMap`. +pub trait UstrMapExt { + /// Creates an empty `UstrMap` using the default value for its hasher. + fn new() -> Self; + + /// Creates an empty `UstrMap` with at least the specified capacity using + /// the default value for its hasher. + fn with_capacity(capacity: usize) -> Self; +} + +impl UstrMapExt for UstrMap { + fn new() -> Self { + UstrMap::default() + } + + fn with_capacity(capacity: usize) -> Self { + UstrMap::with_capacity_and_hasher(capacity, Default::default()) + } +}