Skip to content

Commit

Permalink
Also implement u32 conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Jun 11, 2024
1 parent c9c5530 commit 8e17ae3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Unreleased
- Add function `Direction::iter` which returns an iterator over all the `Direction` enum values
- Add function `RoomXY::neighbors` which returns an iterator over all the valid neighbors of
a given `RoomXY` position
- Implement `JsCollectionIntoValue` and `JsCollectionFromValue` for `IntershardResourceType`
- Implement `JsCollectionIntoValue` and `JsCollectionFromValue` for `IntershardResourceType` and
`u32` to allow `game::resources()` return value to be used as expected

0.21.0 (2024-05-14)
===================
Expand Down
16 changes: 16 additions & 0 deletions src/js_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ impl JsCollectionFromValue for u8 {
}
}

impl JsCollectionIntoValue for u32 {
fn into_value(self) -> JsValue {
JsValue::from_f64(self as f64)
}
}

impl JsCollectionFromValue for u32 {
fn from_value(val: JsValue) -> u32 {
if let Some(val) = val.as_string() {
val.parse::<u32>().expect("expected parseable u32 string")
} else {
val.as_f64().expect("expected number value") as u32
}
}
}

impl<K, V> JsCollectionFromValue for (K, V)
where
K: JsCollectionFromValue,
Expand Down

0 comments on commit 8e17ae3

Please sign in to comment.