Start defining the return type.
This commit is contained in:
parent
b3f97dbb40
commit
2d5593681f
@ -51,6 +51,7 @@ opentelemetry = { version = "0.20.0", optional = true, default-features = false,
|
||||
opentelemetry-otlp = { version = "0.13.0", optional = true }
|
||||
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
|
||||
serde = { version = "1.0.193", optional = true, features = ["derive"] }
|
||||
serde-wasm-bindgen = { version = "0.6.3", optional = true }
|
||||
tokio = { version = "1.30.0", optional = true, default-features = false, features = ["rt", "rt-multi-thread"] }
|
||||
tracing = { version = "0.1.37", optional = true }
|
||||
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
||||
@ -67,7 +68,7 @@ compare = ["tokio/process", "tokio/macros"]
|
||||
foreign_document_test = ["compare", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"]
|
||||
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
||||
event_count = []
|
||||
wasm = ["dep:serde", "dep:wasm-bindgen"]
|
||||
wasm = ["dep:serde", "dep:wasm-bindgen", "dep:serde-wasm-bindgen"]
|
||||
|
||||
# Optimized build for any sort of release.
|
||||
[profile.release-lto]
|
||||
|
1
Makefile
1
Makefile
@ -32,6 +32,7 @@ release:
|
||||
.PHONY: wasm
|
||||
wasm:
|
||||
> cargo build --target=wasm32-unknown-unknown --profile wasm --bin wasm --features wasm
|
||||
> wasm-bindgen --target web --out-dir target/wasm32-unknown-unknown/js target/wasm32-unknown-unknown/wasm/wasm.wasm
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
@ -1,7 +1,17 @@
|
||||
#![no_main]
|
||||
|
||||
use organic::parser::parse_with_settings;
|
||||
use organic::settings::GlobalSettings;
|
||||
use wasm::ParseResult;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
mod wasm;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||
let global_settings = GlobalSettings::default();
|
||||
let rust_parsed = parse_with_settings(org_contents, &global_settings)
|
||||
.map(|document| ParseResult::Success(document.into()))
|
||||
.unwrap_or_else(|err| ParseResult::Error(format!("{:?}", err)));
|
||||
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
|
||||
}
|
||||
|
14
src/wasm/document.rs
Normal file
14
src/wasm/document.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use organic::types::Document;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(tag = "ast_node")]
|
||||
#[serde(rename = "org-data")]
|
||||
pub(crate) struct WasmDocument {}
|
||||
|
||||
impl From<Document<'_>> for WasmDocument {
|
||||
fn from(value: Document) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
4
src/wasm/mod.rs
Normal file
4
src/wasm/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
mod document;
|
||||
mod parse_result;
|
||||
|
||||
pub(crate) use parse_result::ParseResult;
|
14
src/wasm/parse_result.rs
Normal file
14
src/wasm/parse_result.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::document::WasmDocument;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(tag = "status", content = "content")]
|
||||
pub(crate) enum ParseResult {
|
||||
#[serde(rename = "success")]
|
||||
Success(WasmDocument),
|
||||
|
||||
#[serde(rename = "error")]
|
||||
Error(String),
|
||||
}
|
Loading…
Reference in New Issue
Block a user