tauri_api::rpc

Function format_callback

Source
pub fn format_callback<T: Into<Value>, S: AsRef<str> + Display>(
    function_name: S,
    arg: T,
) -> String
Expand description

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"})"#));