From 9cbfcd5faf33a36334cb7c1be96e4d6d36cdb952 Mon Sep 17 00:00:00 2001 From: Kenneth Loeffler Date: Wed, 30 Oct 2024 20:12:51 +0000 Subject: [PATCH] Change type of InstanceBuilder.properties to Vec<(Ustr, Variant)> (#467) --- rbx_dom_weak/src/dom.rs | 2 +- rbx_dom_weak/src/instance.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/rbx_dom_weak/src/dom.rs b/rbx_dom_weak/src/dom.rs index 3b43ea3f..81c942bb 100644 --- a/rbx_dom_weak/src/dom.rs +++ b/rbx_dom_weak/src/dom.rs @@ -123,7 +123,7 @@ impl WeakDom { parent, name: builder.name, class: builder.class, - properties: builder.properties, + properties: builder.properties.into_iter().collect(), }, ); diff --git a/rbx_dom_weak/src/instance.rs b/rbx_dom_weak/src/instance.rs index 9118a8b7..33535ab5 100644 --- a/rbx_dom_weak/src/instance.rs +++ b/rbx_dom_weak/src/instance.rs @@ -1,8 +1,6 @@ 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. @@ -37,7 +35,7 @@ pub struct InstanceBuilder { pub(crate) referent: Ref, pub(crate) name: String, pub(crate) class: Ustr, - pub(crate) properties: UstrMap, + pub(crate) properties: Vec<(Ustr, Variant)>, pub(crate) children: Vec, } @@ -52,7 +50,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: UstrMap::new(), + properties: Vec::new(), children: Vec::new(), } } @@ -67,7 +65,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: UstrMap::with_capacity(capacity), + properties: Vec::with_capacity(capacity), children: Vec::new(), } } @@ -78,7 +76,7 @@ impl InstanceBuilder { referent: Ref::new(), name: String::new(), class: Ustr::default(), - properties: UstrMap::new(), + properties: Vec::new(), children: Vec::new(), } } @@ -124,18 +122,19 @@ impl InstanceBuilder { /// Add a new property to the `InstanceBuilder`. pub fn with_property, V: Into>(mut self, key: K, value: V) -> Self { - self.properties.insert(key.into(), value.into()); + self.properties.push((key.into(), value.into())); self } /// Add a new property to the `InstanceBuilder`. pub fn add_property, V: Into>(&mut self, key: K, value: V) { - self.properties.insert(key.into(), value.into()); + self.properties.push((key.into(), value.into())); } /// Check if the `InstanceBuilder` already has a property with the given key. pub fn has_property>(&self, key: K) -> bool { - self.properties.contains_key(&key.into()) + let key = key.into(); + self.properties.iter().any(|(k, _)| *k == key) } /// Add multiple properties to the `InstanceBuilder` at once.