Skip to content

Commit

Permalink
Change type of InstanceBuilder.properties to Vec<(Ustr, Variant)> (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler authored Oct 30, 2024
1 parent e909f45 commit 9cbfcd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rbx_dom_weak/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl WeakDom {
parent,
name: builder.name,
class: builder.class,
properties: builder.properties,
properties: builder.properties.into_iter().collect(),
},
);

Expand Down
17 changes: 8 additions & 9 deletions rbx_dom_weak/src/instance.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -37,7 +35,7 @@ pub struct InstanceBuilder {
pub(crate) referent: Ref,
pub(crate) name: String,
pub(crate) class: Ustr,
pub(crate) properties: UstrMap<Variant>,
pub(crate) properties: Vec<(Ustr, Variant)>,
pub(crate) children: Vec<InstanceBuilder>,
}

Expand All @@ -52,7 +50,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: UstrMap::new(),
properties: Vec::new(),
children: Vec::new(),
}
}
Expand All @@ -67,7 +65,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: UstrMap::with_capacity(capacity),
properties: Vec::with_capacity(capacity),
children: Vec::new(),
}
}
Expand All @@ -78,7 +76,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name: String::new(),
class: Ustr::default(),
properties: UstrMap::new(),
properties: Vec::new(),
children: Vec::new(),
}
}
Expand Down Expand Up @@ -124,18 +122,19 @@ impl InstanceBuilder {

/// Add a new property to the `InstanceBuilder`.
pub fn with_property<K: Into<Ustr>, V: Into<Variant>>(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<K: Into<Ustr>, V: Into<Variant>>(&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<K: Into<Ustr>>(&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.
Expand Down

0 comments on commit 9cbfcd5

Please sign in to comment.