Skip to content

Commit

Permalink
Merge branch 'main' into snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Mar 16, 2024
2 parents ff8db92 + 2b49b64 commit 9868324
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Unreleased
which returns a `Result<&'static [ResourceType], StoreObjectConversionError>`
- Add missing `StoreObject::Reactor` to the `seasonal-season-5` feature
- Implement `Serialize` and `Deserialize` for `RoomStatus`
- Add function `JsHashMap::entries`

### Bugfixes:

Expand Down
25 changes: 25 additions & 0 deletions src/js_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ where
}
}

impl<K, V> JsHashMap<K, V>
where
K: JsCollectionFromValue,
V: JsCollectionFromValue,
{
pub fn entries(&self) -> impl Iterator<Item = (K, V)> {
let array = Object::entries(self.map.unchecked_ref());

OwnedArrayIter::new(array)
}
}

impl<K, V> JsHashMap<K, V>
where
K: JsCollectionIntoValue,
Expand Down Expand Up @@ -307,3 +319,16 @@ impl JsCollectionFromValue for u8 {
}
}
}

impl<K, V> JsCollectionFromValue for (K, V)
where
K: JsCollectionFromValue,
V: JsCollectionFromValue,
{
fn from_value(val: JsValue) -> Self {
let val: &Array = val.dyn_ref().expect("expected tuple of length 2");
let k = K::from_value(val.get(0));
let v = V::from_value(val.get(1));
(k, v)
}
}

0 comments on commit 9868324

Please sign in to comment.