Skip to content

Commit

Permalink
Allow string versions of directions
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Mar 3, 2024
1 parent 5d61429 commit 4153be8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/constants/small_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ impl JsCollectionIntoValue for Direction {

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

Self::from_u8(n).expect("unknown direction")
}
Expand Down

0 comments on commit 4153be8

Please sign in to comment.