This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm) Export
Vec<Block>
to wasm.
So, `wasm-bindgen` does not support `Vec<T>` (see rustwasm/wasm-bindgen#111), so my quick and dirty solution right now is to serialize the vector to JSON, and parse it from the JS land.
- Loading branch information
Showing
4 changed files
with
13 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
use super::Input; | ||
use serde_json as json; | ||
|
||
#[derive(Debug, PartialEq)] | ||
#[derive(Debug, PartialEq, Serialize)] | ||
pub struct Block<'a> { | ||
pub name: (&'a [u8], &'a [u8]), | ||
pub name: (Input<'a>, Input<'a>), | ||
pub attributes: Option<json::Value>, | ||
pub inner_blocks: Vec<Block<'a>> | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
use serde_json as json; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub fn root(input: &str) -> bool { | ||
if let Ok(_) = super::root(input.as_bytes()) { | ||
true | ||
pub fn root(input: &str) -> String { | ||
if let Ok((_remaining, blocks)) = super::root(input.as_bytes()) { | ||
json::to_string(&blocks).unwrap() | ||
} else { | ||
false | ||
"".to_owned() | ||
} | ||
} |