pub fn format_callback_result<T: Serialize, E: Serialize>(
  result: Result<T, E>,
  success_callback: impl AsRef<str>,
  error_callback: impl AsRef<str>,
) -> crate::Result<String> {
  let rpc = match result {
    Ok(res) => format_callback(success_callback, serde_json::to_value(res)?),
    Err(err) => format_callback(error_callback, serde_json::to_value(err)?),
  };
  Ok(rpc)
}
/// Formats a Result type to its Promise response.
/// Useful for Promises handling.
/// If the Result `is_ok()`, the callback will be the `success_callback` function name and the argument will be the Ok value.
/// If the Result `is_err()`, the callback will be the `error_callback` function name and the argument will be the Err value.
///
/// * `result` the Result to check
/// * `success_callback` the function name of the Ok callback. Usually the `resolve` of the JS Promise.
/// * `error_callback` the function name of the Err callback. Usually the `reject` of the JS Promise.
///
/// Note that the callback strings are automatically generated by the `invoke` helper.
///
/// # Examples
/// ```
/// use tauri_api::rpc::format_callback_result;
/// let res: Result<u8, &str> = Ok(5);
/// let cb = format_callback_result(res, "success_cb", "error_cb").expect("failed to format");
/// assert!(cb.contains(r#"window["success_cb"](5)"#));
///
/// let res: Result<&str, &str> = Err("error message here");
/// let cb = format_callback_result(res, "success_cb", "error_cb").expect("failed to format");
/// assert!(cb.contains(r#"window["error_cb"]("error message here")"#));
/// ```
Formats a Result type to its Promise response.
Useful for Promises handling.
If the Result `is_ok()`, the callback will be the `success_callback` function name and the argument will be the Ok value.
If the Result `is_err()`, the callback will be the `error_callback` function name and the argument will be the Err value.

`result` the Result to check
`success_callback` the function name of the Ok callback. Usually the `resolve` of the JS Promise.
`error_callback` the function name of the Err callback. Usually the `reject` of the JS Promise.

Note that the callback strings are automatically generated by the `invoke` helper.
Formats a Result type to its Promise response . Useful for Promises handling . If the Result ` is_ok () ` the callback will be the ` success_callback ` function name and the argument will be the Ok value . If the Result ` is_err () ` the callback will be the ` error_callback ` function name and the argument will be the Err value . ` result ` the Result to check ` success_callback ` the function name of the Ok callback . Usually the ` resolve ` of the JS Promise . ` error_callback ` the function name of the Err callback . Usually the ` reject ` of the JS Promise . Note that the callback strings are automatically generated by the ` invoke ` helper .
pub fn format_callback_result<T: Serialize, E: Serialize>(
  result: Result<T, E>,
  success_callback: impl AsRef<str>,
  error_callback: impl AsRef<str>,
) -> crate::Result<String> {
  let rpc = match result {
    Ok(res) => format_callback(success_callback, serde_json::to_value(res)?),
    Err(err) => format_callback(error_callback, serde_json::to_value(err)?),
  };
  Ok(rpc)
}
pub fn format_callback_result < T : Serialize , E : Serialize > ( result : Result < T , E > , success_callback : impl AsRef < str > , error_callback : impl AsRef < str > , ) -> crate :: Result < String > { let rpc = match result { Ok ( res ) => format_callback ( success_callback , serde_json :: to_value ( res ) ? ) , Err ( err ) => format_callback ( error_callback , serde_json :: to_value ( err ) ? ) , } ; Ok ( rpc ) }
Formats a Result type to its Promise response.
Formats a Result type to its Promise response .
result
Result<T, E>
success_callback
impl AsRef<str>
error_callback
impl AsRef<str>
result
Result<T, E>
success_callback
impl AsRef<str>
error_callback
impl AsRef<str>
examples
```
use tauri_api::rpc::format_callback_result;
let res: Result = Ok(5);
let cb = format_callback_result(res, "success_cb", "error_cb").expect("failed to format");
assert!(cb.contains(r#"window["success_cb"](5)"#)).

let res: Result<&str, &str> = Err("error message here");
let cb = format_callback_result(res, "success_cb", "error_cb").expect("failed to format");
assert!(cb.contains(r#"window["error_cb"]("error message here")"#));
```
` ` ` use tauri_api :: rpc :: format_callback_result ; let res : Result = Ok ( 5 ) ; let cb = format_callback_result ( res " success_cb " " error_cb " ) . expect ( " failed to format " ) ; assert! ( cb . contains ( r# " window [ " success_cb " ] ( 5 ) " # )) . let res : Result<&str &str > = Err ( " error message here " ) ; let cb = format_callback_result ( res " success_cb " " error_cb " ) . expect ( " failed to format " ) ; assert! ( cb . contains ( r# " window [ " error_cb " ] ( " error message here " ) " # )) ; ` ` `