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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/// This macro will generate a wrapper for mapping a js_sys::Function with type fn(T, T, T, T) -> Promise<()>
/// to native function
/// # Example:
/// For macro calling: of!(of2, a: T0, b: T1);
/// Will generate code:
/// ```rust,no_run
/// pub fn of2<
/// 'a,
/// 'b: 'a,
/// T0: TryInto<wasm_bindgen::JsValue> + Clone,
/// T1: TryInto<wasm_bindgen::JsValue> + Clone,
/// >(
/// func: &js_sys::Function,
/// ) -> Box<
/// dyn Fn(
/// T0,
/// T1,
/// ) -> std::pin::Pin<
/// Box<dyn std::future::Future<Output = rings_core::error::Result<()>> + 'b>,
/// >,
/// >
/// where
/// T0::Error: std::fmt::Debug,
/// T1::Error: std::fmt::Debug,
/// T0: 'b,
/// T1: 'b,
/// {
/// let func = func.clone();
/// Box::new(
/// move |a: T0,
/// b: T1|
/// -> std::pin::Pin<
/// Box<dyn std::future::Future<Output = rings_core::error::Result<()>>>,
/// > {
/// let func = func.clone();
/// Box::pin(async move {
/// let func = func.clone();
/// let params = js_sys::Array::new();
/// let a: wasm_bindgen::JsValue = a
/// .clone()
/// .try_into()
/// .map_err(|e| rings_core::error::Error::JsError(format!("{:?}", e)))?;
/// params.push(&a);
/// let b: wasm_bindgen::JsValue = b
/// .clone()
/// .try_into()
/// .map_err(|e| rings_core::error::Error::JsError(format!("{:?}", e)))?;
/// params.push(&b);
/// wasm_bindgen_futures::JsFuture::from(js_sys::Promise::from(
/// func.apply(&wasm_bindgen::JsValue::NULL, ¶ms)
/// .map_err(|e| rings_core::error::Error::from(js_sys::Error::from(e)))?,
/// ))
/// .await
/// .map_err(|e| rings_core::error::Error::from(js_sys::Error::from(e)))?;
/// Ok(())
/// })
/// },
/// )
/// }
/// ```
of!;
of!;
of!;
of!;