Skip to content

Commit

Permalink
Add UstrMap helper trait, use UstrMap::new in InstanceBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler committed Oct 29, 2024
1 parent e214c1b commit d403d6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rbx_dom_weak/src/instance.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -50,7 +52,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: UstrMap::default(),
properties: UstrMap::new(),
children: Vec::new(),
}
}
Expand All @@ -61,7 +63,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name: String::new(),
class: Ustr::default(),
properties: UstrMap::default(),
properties: UstrMap::new(),
children: Vec::new(),
}
}
Expand Down
20 changes: 20 additions & 0 deletions rbx_dom_weak/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<V> UstrMapExt for UstrMap<V> {
fn new() -> Self {
UstrMap::default()
}

fn with_capacity(capacity: usize) -> Self {
UstrMap::with_capacity_and_hasher(capacity, Default::default())
}
}

0 comments on commit d403d6e

Please sign in to comment.