cxmr_wasm/
lib.rs

1//! Crypto-bank WebAssembly module.
2
3#[macro_use]
4extern crate cfg_if;
5
6#[cfg(target_arch = "wasm32")]
7extern crate wasm_bindgen;
8
9#[cfg(target_arch = "wasm32")]
10extern crate cxmr_currency;
11
12cfg_if! {
13    // When the `console_error_panic_hook` feature is enabled, we can call the
14    // `set_panic_hook` function to get better error messages if we ever panic.
15    if #[cfg(target_arch = "wasm32")] {
16        extern crate console_error_panic_hook;
17        #[allow(unused_imports)]
18        use console_error_panic_hook::set_once as set_panic_hook;
19    }
20}
21
22cfg_if! {
23    // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
24    // allocator.
25    if #[cfg(target_arch = "wasm32")] {
26        extern crate wee_alloc;
27        #[global_allocator]
28        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
29    }
30}
31
32#[cfg(target_arch = "wasm32")]
33pub mod currency {
34    use std::str::FromStr;
35
36    use wasm_bindgen::prelude::*;
37
38    use cxmr_currency::CurrencyPair;
39
40    #[wasm_bindgen]
41    pub fn split_pair(s: &str) -> CurrencyPair {
42        CurrencyPair::from_str(s).unwrap()
43    }
44}