pub fn serialize_js<T: Serialize>(value: &T) -> Result<String>
Expand description

Transforms & escapes a JSON value.

This is a convenience function for serialize_js_with, simply allocating the result to a String.

For usage in functions where performance is more important than code readability, see serialize_js_with.

Examples

use tauri::{Manager, api::ipc::serialize_js};
use serde::Serialize;

#[derive(Serialize)]
struct Foo {
  bar: String,
}

#[derive(Serialize)]
struct Bar {
  baz: u32,
}

tauri::Builder::default()
  .setup(|app| {
    let window = app.get_window("main").unwrap();
    window.eval(&format!(
      "console.log({}, {})",
      serialize_js(&Foo { bar: "bar".to_string() }).unwrap(),
      serialize_js(&Bar { baz: 0 }).unwrap()),
    )?;
    Ok(())
  });