geoarrow_wasm/
utils.rs

1use arrow2::offset::OffsetsBuffer;
2#[cfg(feature = "console_error_panic_hook")]
3use wasm_bindgen::prelude::*;
4
5#[cfg(feature = "console_error_panic_hook")]
6#[wasm_bindgen]
7pub fn set_panic_hook() {
8    // When the `console_error_panic_hook` feature is enabled, we can call the
9    // `set_panic_hook` function at least once during initialization, and then
10    // we will get better error messages if our code ever panics.
11    //
12    // For more details see
13    // https://github.com/rustwasm/console_error_panic_hook#readme
14    console_error_panic_hook::set_once();
15}
16
17/// Convert vec to OffsetsBuffer
18pub fn vec_to_offsets(v: Vec<i32>) -> OffsetsBuffer<i64> {
19    let offsets = unsafe { OffsetsBuffer::new_unchecked(v.into()) };
20    (&offsets).into()
21}
22
23// A macro to provide `println!(..)`-style syntax for `console.log` logging.
24#[cfg(target_arch = "wasm32")]
25#[macro_export]
26macro_rules! log {
27    ( $( $t:tt )* ) => {
28        web_sys::console::log_1(&format!( $( $t )* ).into());
29    }
30}
31
32#[cfg(not(target_arch = "wasm32"))]
33#[macro_export]
34macro_rules! log {
35    ( $( $t:tt )* ) => {
36        println!("LOG - {}", format!( $( $t )* ));
37    }
38}