chart_js_rs/objects/
mod.rs1mod chart_objects;
2mod helper_objects;
3mod methods;
4
5pub use chart_objects::*;
6pub use helper_objects::*;
7
8use js_sys::Reflect;
9use serde::Deserialize;
10use wasm_bindgen::JsValue;
11
12fn rationalise_1_level<const N: usize, T: for<'a> Deserialize<'a>>(
13 obj: &JsValue,
14 name: &'static str,
15 f: impl Fn(T),
16) {
17 if let Ok(a) = Reflect::get(obj, &name.into()) {
18 if a == JsValue::UNDEFINED {
20 return;
21 }
22
23 if let Ok(o) = serde_wasm_bindgen::from_value::<T>(a) {
24 f(o)
25 }
26 }
27}
28fn rationalise_2_levels<const N: usize, T: for<'a> Deserialize<'a>>(
29 obj: &JsValue,
30 name: (&'static str, &'static str),
31 f: impl Fn(JsValue, T),
32) {
33 if let Ok(a) = Reflect::get(obj, &name.0.into()) {
34 if a == JsValue::UNDEFINED {
36 return;
37 }
38
39 if let Ok(b) = Reflect::get(&a, &name.1.into()) {
40 if b == JsValue::UNDEFINED {
42 return;
43 }
44
45 if let Ok(o) = serde_wasm_bindgen::from_value::<T>(b) {
46 f(a, o)
47 }
48 }
49 }
50}