1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
//! WASM bindings — 浏览器端调用入口 //! //! 在 wasm32 target 上编译时使用 wasm-bindgen 导出函数。 //! 在 native target 上此模块为空。 #[cfg(target_arch = "wasm32")] mod imp { use wasm_bindgen::prelude::*; use crate::search; use crate::similarity; use crate::curation; #[wasm_bindgen] pub fn tokenize(text: &str) -> Box<[JsValue]> { search::tokenize(text) .into_iter() .map(|s| JsValue::from_str(&s)) .collect::<Vec<_>>() .into_boxed_slice() } #[wasm_bindgen] pub fn lcs_similarity(a: &str, b: &str) -> f64 { similarity::lcs_similarity(a, b) } #[wasm_bindgen] pub fn canonical_hash(content: &str) -> String { similarity::canonical_hash(content) } #[wasm_bindgen] pub fn assess_text_quality(content: &str) -> f64 { curation::assess_text_quality(content) } } #[cfg(target_arch = "wasm32")] pub use imp::*;