This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get the WASM bindings working end-to-end using Serde, but by awkwardl…
…y forcing
- Loading branch information
1 parent
098d9b7
commit c3e4504
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::collections::HashMap; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::tag::{Tags, TagsWrite}; | ||
use crate::{tags_to_lanes, DrivingSide, Locale, TagsToLanesConfig}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Input { | ||
key_values: HashMap<String, String>, | ||
drive_on_right: bool, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn js_tags_to_lanes(val: &JsValue) -> JsValue { | ||
console_error_panic_hook::set_once(); | ||
|
||
let input: Input = val.into_serde().unwrap(); | ||
|
||
let mut config = TagsToLanesConfig::default(); | ||
config.error_on_warnings = false; | ||
config.include_separators = true; | ||
|
||
let locale = Locale::builder() | ||
.driving_side(if input.drive_on_right { | ||
DrivingSide::Right | ||
} else { | ||
DrivingSide::Left | ||
}) | ||
.build(); | ||
|
||
let mut tags = Tags::default(); | ||
for (key, value) in input.key_values { | ||
tags.checked_insert(key, value).unwrap(); | ||
} | ||
let lanes = tags_to_lanes(&tags, &locale, &config).unwrap(); | ||
JsValue::from_serde(&lanes).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters