pub fn format_callback<T: Into<JsonValue>, S: AsRef<str>>(function_name: S, arg: T) -> String {
  format!(
    r#"
      if (window["{fn}"]) {{
        window["{fn}"]({arg})
      }} else {{
        console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
      }}
    "#,
    fn = function_name.as_ref(),
    arg = arg.into().to_string()
  )
}
/// Formats a function name and argument to be evaluated as callback.
///
/// # Examples
/// ```
/// use tauri_api::rpc::format_callback;
/// // callback with a string argument
/// let cb = format_callback("callback-function-name", "the string response");
/// assert!(cb.contains(r#"window["callback-function-name"]("the string response")"#));
/// ```
///
/// ```
/// use tauri_api::rpc::format_callback;
/// use serde::Serialize;
/// // callback with JSON argument
/// #[derive(Serialize)]
/// struct MyResponse {
///   value: String
/// }
/// let cb = format_callback("callback-function-name", serde_json::to_value(&MyResponse {
///   value: "some value".to_string()
/// }).expect("failed to serialize"));
/// assert!(cb.contains(r#"window["callback-function-name"]({"value":"some value"})"#));
/// ```
Formats a function name and argument to be evaluated as callback.
Formats a function name and argument to be evaluated as callback .
pub fn format_callback<T: Into<JsonValue>, S: AsRef<str>>(function_name: S, arg: T) -> String {
  format!(
    r#"
      if (window["{fn}"]) {{
        window["{fn}"]({arg})
      }} else {{
        console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
      }}
    "#,
    fn = function_name.as_ref(),
    arg = arg.into().to_string()
  )
}
pub fn format_callback < T : Into < JsonValue > , S : AsRef < str > > ( function_name : S , arg : T ) -> String { format ! ( r#"
      if (window["{fn}"]) {{
        window["{fn}"]({arg})
      }} else {{
        console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
      }}
    "# fn function_name as_ref ( ) arg arg into ( ) to_string ( ) ) }
Formats a function name and argument to be evaluated as callback.
Formats a function name and argument to be evaluated as callback .
function_name
S
arg
T
function_name
S
arg
T
examples
```
use tauri_api::rpc::format_callback;
callback with a string argument
let cb = format_callback("callback-function-name", "the string response");
assert!(cb.contains(r#"window["callback-function-name"]("the string response")"#));
```

```
use tauri_api::rpc::format_callback;
use serde::Serialize;
callback with JSON argument
` ` ` use tauri_api :: rpc :: format_callback ; callback with a string argument let cb = format_callback ( " callback - function - name " " the string response " ) ; assert! ( cb . contains ( r# " window [ " callback - function - name " ] ( " the string response " ) " # )) ; ` ` ` ` ` ` use tauri_api :: rpc :: format_callback ; use serde :: Serialize ; callback with JSON argument
[derive(serialize)]
struct MyResponse {
value: String
}
let cb = format_callback("callback-function-name", serde_json::to_value(&MyResponse {
value: "some value".to_string()
}).expect("failed to serialize"));
assert!(cb.contains(r#"window["callback-function-name"]({"value":"some value"})"#));
```
struct MyResponse { value : String } let cb = format_callback ( " callback - function - name " serde_json :: to_value ( &MyResponse { value : " some value " . to_string () } ) . expect ( " failed to serialize " )) ; assert! ( cb . contains ( r# " window [ " callback - function - name " ] ( { " value " : " some value " } ) " # )) ; ` ` `