WebAssembly compatibility
Closed this issue · 1 comments
Ptrskay3 commented
I'm trying to use this crate with wasm-bindgen
, and it seems that using u32 indices does not work. Specifically this line
Line 80 in 4e2dbf4
panics if the crate is built on wasm target. Here's a minimal example to reproduce the issue:
use kiddo::{float::kdtree::KdTree};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct KdTreeWasm {
tree: KdTree<f64, u64, 2, 32, u32>,
}
#[wasm_bindgen]
impl KdTreeWasm {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
let tree: KdTree<f64, u64, 2, 32, u32> = KdTree::with_capacity(5);
Self { tree }
}
}
and on the JavaScript side, simply just initialize:
import('../pkg/index.js').then({ KdTreeWasm } => {
let tree = new KdTreeWasm();
});
and this'll panic at attempt to multiply with an overflow
.
Is this behaviour expected? Am I missing something?
If I'm not mistaken, capacity_with_bucket_size
only works with u32 if #[cfg(target_pointer_width = "64")]
.