fn _error_hndlr_add(arg1 : Variant, arg2 : Variant) -> Result < Variant, Box < dyn std :: error :: Error >> { log :: trace ! ("{} called", stringify ! (xl_add)) ; let(arg1, arg2) = if ! args_obj . is_missing_or_null() { if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < (f64, f64) > (stringify ! (xl_add "arg1,arg2" "Args"), & key) { v } else { if arg1 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add) . to_string(), stringify ! (arg1) . to_string()))) ; } let arg1 = f64 :: from(& arg1) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg1), arg1) ; if arg2 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add) . to_string(), stringify ! (arg2) . to_string()))) ; } let arg2 = f64 :: from(& arg2) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg2), arg2) ; ; ; (arg1, arg2) } } else { if arg1 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add) . to_string(), stringify ! (arg1) . to_string()))) ; } let arg1 = f64 :: from(& arg1) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg1), arg1) ; if arg2 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add) . to_string(), stringify ! (arg2) . to_string()))) ; } let arg2 = f64 :: from(& arg2) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg2), arg2) ; ; ; (arg1, arg2) } ; let res = std :: panic :: catch_unwind(|| add(arg1, arg2)) ; match res { Ok(res) => { let res = res ? ; log :: trace ! ("Results [{:?}]", res) ; Ok(Variant :: from(res)) } Err(_) => Ok(Variant :: from("Unexpected error while calling function")), } } #[no_mangle] pub extern "stdcall" fn xl_add(arg1 : LPXLOPER12, arg2 : LPXLOPER12) -> LPXLOPER12 { match _error_hndlr_add(Variant :: from(arg1), Variant :: from(arg2)) { Ok(v) => { LPXLOPER12 :: from(v) }, Err(e) => { log :: error ! ("{}", e . to_string()) ; LPXLOPER12 :: from(Variant :: from(e . to_string() . as_str())) }, } } pub(crate) fn register_add(reg : & xladd :: registrator :: Reg) { reg . add("xl_add", "QQQ$", "arg1,arg2", "", " and ", & []) ; } fn add(arg1 : f64, arg2 : f64) -> Result < f64, Box < dyn std :: error :: Error > > { Ok(arg1 + arg2) } fn _error_hndlr_add_array(v : Variant) -> Result < Variant, Box < dyn std :: error :: Error >> { log :: trace ! ("{} called", stringify ! (xl_add_array)) ; let(v) = if ! args_obj . is_missing_or_null() { if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < (f64) > (stringify ! (xl_add_array "v" "Args"), & key) { v } else { if v . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_array) . to_string(), stringify ! (v) . to_string()))) ; } let v = < Vec < f64 >> :: from(& v) ; log :: trace ! ("{}:[{:?}]", stringify ! (v), v) ; ; let v = v . as_slice() ; ; (v) } } else { if v . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_array) . to_string(), stringify ! (v) . to_string()))) ; } let v = < Vec < f64 >> :: from(& v) ; log :: trace ! ("{}:[{:?}]", stringify ! (v), v) ; ; let v = v . as_slice() ; ; (v) } ; let res = std :: panic :: catch_unwind(|| add_array(v)) ; match res { Ok(res) => { let res = res ? ; log :: trace ! ("Results [{:?}]", res) ; Ok(Variant :: from(res)) } Err(_) => Ok(Variant :: from("Unexpected error while calling function")), } } #[no_mangle] pub extern "stdcall" fn xl_add_array(v : LPXLOPER12) -> LPXLOPER12 { match _error_hndlr_add_array(Variant :: from(v)) { Ok(v) => { LPXLOPER12 :: from(v) }, Err(e) => { log :: error ! ("{}", e . to_string()) ; LPXLOPER12 :: from(Variant :: from(e . to_string() . as_str())) }, } } pub(crate) fn register_add_array(reg : & xladd :: registrator :: Reg) { reg . add("xl_add_array", "QQ$", "v", "", "returns the sum0 and This function adds any number of values together", & ["array of f64"]) ; } #[doc = " This function adds any number of values together"] #[doc = " * v - array of f64"] #[doc = " * ret - returns the sum0"] fn add_array(v : & [f64]) -> Result < f64, Box < dyn std :: error :: Error > > { Ok(v . iter() . sum()) } fn _error_hndlr_add_array_v2(v : Variant) -> Result < Variant, Box < dyn std :: error :: Error >> { log :: trace ! ("{} called", stringify ! (xl_add_array_v2)) ; let(v) = if ! args_obj . is_missing_or_null() { if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < (f64) > (stringify ! (xl_add_array_v2 "v" "Args"), & key) { v } else { if v . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_array_v2) . to_string(), stringify ! (v) . to_string()))) ; } let v = < Vec < f64 >> :: from(& v) ; log :: trace ! ("{}:[{:?}]", stringify ! (v), v) ; ; let v = v . as_slice() ; ; (v) } } else { if v . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_array_v2) . to_string(), stringify ! (v) . to_string()))) ; } let v = < Vec < f64 >> :: from(& v) ; log :: trace ! ("{}:[{:?}]", stringify ! (v), v) ; ; let v = v . as_slice() ; ; (v) } ; let res = std :: panic :: catch_unwind(|| add_array_v2(v)) ; match res { Ok(res) => { let res = res ? ; log :: trace ! ("Results [{:?}]", res) ; Ok(Variant :: from(res)) } Err(_) => Ok(Variant :: from("Unexpected error while calling function")), } } #[no_mangle] pub extern "stdcall" fn xl_add_array_v2(v : LPXLOPER12) -> LPXLOPER12 { match _error_hndlr_add_array_v2(Variant :: from(v)) { Ok(v) => { LPXLOPER12 :: from(v) }, Err(e) => { log :: error ! ("{}", e . to_string()) ; LPXLOPER12 :: from(Variant :: from(e . to_string() . as_str())) }, } } pub(crate) fn register_add_array_v2(reg : & xladd :: registrator :: Reg) { reg . add("xl_add_array_v2", "QQ$", "v", "", "returns the sum and This function adds any number of values together", & ["array of f64"]) ; } #[doc = " This function adds any number of values together"] #[doc = " * v - array of f64"] #[doc = " * ret - returns the sum"] fn add_array_v2(v : & [f64]) -> Result < (Vec < f64 >, usize), Box < dyn std :: error :: Error > > { Ok((v . to_vec(), 2)) } fn _error_hndlr_add_str(a : Variant, b : Variant) -> Result < Variant, Box < dyn std :: error :: Error >> { log :: trace ! ("{} called", stringify ! (xl_add_str)) ; let(a, b) = if ! args_obj . is_missing_or_null() { if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < (str, str) > (stringify ! (xl_add_str "a,b" "Args"), & key) { v } else { if a . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_str) . to_string(), stringify ! (a) . to_string()))) ; } let a = String :: from(& a) ; log :: trace ! ("{}:[{:?}]", stringify ! (a), a) ; if b . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_str) . to_string(), stringify ! (b) . to_string()))) ; } let b = String :: from(& b) ; log :: trace ! ("{}:[{:?}]", stringify ! (b), b) ; ; let a = a . as_str() ; let b = b . as_str() ; ; (a, b) } } else { if a . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_str) . to_string(), stringify ! (a) . to_string()))) ; } let a = String :: from(& a) ; log :: trace ! ("{}:[{:?}]", stringify ! (a), a) ; if b . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_str) . to_string(), stringify ! (b) . to_string()))) ; } let b = String :: from(& b) ; log :: trace ! ("{}:[{:?}]", stringify ! (b), b) ; ; let a = a . as_str() ; let b = b . as_str() ; ; (a, b) } ; let res = std :: panic :: catch_unwind(|| add_str(a, b)) ; match res { Ok(res) => { let res = res ? ; log :: trace ! ("Results [{:?}]", res) ; Ok(Variant :: from(res)) } Err(_) => Ok(Variant :: from("Unexpected error while calling function")), } } #[no_mangle] pub extern "stdcall" fn xl_add_str(a : LPXLOPER12, b : LPXLOPER12) -> LPXLOPER12 { match _error_hndlr_add_str(Variant :: from(a), Variant :: from(b)) { Ok(v) => { LPXLOPER12 :: from(v) }, Err(e) => { log :: error ! ("{}", e . to_string()) ; LPXLOPER12 :: from(Variant :: from(e . to_string() . as_str())) }, } } pub(crate) fn register_add_str(reg : & xladd :: registrator :: Reg) { reg . add("xl_add_str", "QQQ$", "a,b", "", "returns the sum and This function adds any number of values together", & []) ; } #[doc = " This function adds any number of values together"] #[doc = " * v - array of f64"] #[doc = " * ret - returns the sum"] fn add_str(a : & str, b : & str) -> Result < String, Box < dyn std :: error :: Error > > { Ok([a, b] . join("-")) } fn _error_hndlr_add_str_2(a : Variant) -> Result < Variant, Box < dyn std :: error :: Error >> { log :: trace ! ("{} called", stringify ! (my_foo)) ; let(a) = if ! args_obj . is_missing_or_null() { if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < (str) > (stringify ! (my_foo "a" "Args"), & key) { v } else { if a . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_str_2) . to_string(), stringify ! (a) . to_string()))) ; } let a = < Vec < String >> :: from(& a) ; let a = a . iter() . map(AsRef :: as_ref) . collect :: < Vec < _ >> () ; log :: trace ! ("{}:[{:?}]", stringify ! (a), a) ; ; let a = a . as_slice() ; ; (a) } } else { if a . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_str_2) . to_string(), stringify ! (a) . to_string()))) ; } let a = < Vec < String >> :: from(& a) ; let a = a . iter() . map(AsRef :: as_ref) . collect :: < Vec < _ >> () ; log :: trace ! ("{}:[{:?}]", stringify ! (a), a) ; ; let a = a . as_slice() ; ; (a) } ; let res = std :: panic :: catch_unwind(|| add_str_2(a)) ; match res { Ok(res) => { let res = res ? ; log :: trace ! ("Results [{:?}]", res) ; Ok(Variant :: from(res)) } Err(_) => Ok(Variant :: from("Unexpected error while calling function")), } } #[no_mangle] pub extern "stdcall" fn my_foo(a : LPXLOPER12) -> LPXLOPER12 { match _error_hndlr_add_str_2(Variant :: from(a)) { Ok(v) => { LPXLOPER12 :: from(v) }, Err(e) => { log :: error ! ("{}", e . to_string()) ; LPXLOPER12 :: from(Variant :: from(e . to_string() . as_str())) }, } } pub(crate) fn register_add_str_2(reg : & xladd :: registrator :: Reg) { reg . add("my_foo", "QQ$", "a", "OptionPricing", " and ", & []) ; } fn add_str_2(a : & [& str]) -> Result < (Vec < String >, usize), Box < dyn std :: error :: Error > > { Ok((vec ! [a . join("-")], 1)) } fn _error_hndlr_add_cache(result_obj : Variant, args_obj : Variant, arg1 : Variant, arg2 : Variant) -> Result < Variant, Box < dyn std :: error :: Error >> { log :: trace ! ("{} called", stringify ! (xl_add_cache)) ; let(arg1, arg2) = if ! args_obj . is_missing_or_null() { if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < (f64, f64) > (stringify ! (xl_add_cache "arg1,arg2" "Args"), & key) { v } else { if arg1 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_cache) . to_string(), stringify ! (arg1) . to_string()))) ; } let arg1 = f64 :: from(& arg1) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg1), arg1) ; if arg2 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_cache) . to_string(), stringify ! (arg2) . to_string()))) ; } let arg2 = f64 :: from(& arg2) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg2), arg2) ; ; ; (arg1, arg2) } } else { if arg1 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_cache) . to_string(), stringify ! (arg1) . to_string()))) ; } let arg1 = f64 :: from(& arg1) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg1), arg1) ; if arg2 . is_missing_or_null() { return Err(Box :: new(xladd :: variant :: XLAddError :: MissingArgument(stringify ! (add_cache) . to_string(), stringify ! (arg2) . to_string()))) ; } let arg2 = f64 :: from(& arg2) ; log :: trace ! ("{}:[{:?}]", stringify ! (arg2), arg2) ; ; ; (arg1, arg2) } ; if ! result_obj . is_missing_or_null() { let key = String :: from(& result_obj) ; f64, f64 if let Some(v) = xladd :: obj_store :: CACHE . get_cached_object :: < f64 > (stringify ! (xl_add_cache "arg1,arg2"), & key) { return Ok(Variant :: from(v)) ; } } let res = std :: panic :: catch_unwind(|| add_cache(arg1, arg2)) ; match res { Ok(res) => { let res = res ? ; if ! result_obj . is_missing_or_null() { if ! args_obj . is_missing_or_null() { f64, f64 let key = String :: from(& args_obj) ; let new_key = xladd :: obj_store :: CACHE . store_to_cache(stringify ! (xl_add_cache "arg1,arg2"), & key, & res) ; return Ok(Variant :: from(new_key . as_str())) ; } else { let key = String :: from(& result_obj) ; let new_key = xladd :: obj_store :: CACHE . store_to_cache(stringify ! (xl_add_cache "arg1,arg2"), & key, & res) ; return Ok(Variant :: from(new_key . as_str())) ; } } log :: trace ! ("Results [{:?}]", res) ; Ok(Variant :: from(res)) } Err(_) => Ok(Variant :: from("Unexpected error while calling function")), } } #[no_mangle] pub extern "stdcall" fn xl_add_cache(result_obj : LPXLOPER12, args_obj : LPXLOPER12, arg1 : LPXLOPER12, arg2 : LPXLOPER12) -> LPXLOPER12 { match _error_hndlr_add_cache(Variant :: from(result_obj), Variant :: from(args_obj), Variant :: from(arg1), Variant :: from(arg2)) { Ok(v) => { LPXLOPER12 :: from(v) }, Err(e) => { log :: error ! ("{}", e . to_string()) ; LPXLOPER12 :: from(Variant :: from(e . to_string() . as_str())) }, } } pub(crate) fn register_add_cache(reg : & xladd :: registrator :: Reg) { reg . add("xl_add_cache", "QQQ$", "arg1,arg2", "OptionPricing", " and ", & []) ; } fn add_cache(arg1 : f64, arg2 : f64) -> Result < f64, Box < dyn std :: error :: Error > > { Ok(arg1 + arg2) }