Show case how to use pretty json

This commit is contained in:
Tony
2024-10-03 20:35:19 +08:00
parent 4f13a03401
commit 73f365d3f0
3 changed files with 29 additions and 2 deletions
+17
View File
@@ -254,6 +254,23 @@ impl<R: Runtime> Builder<R> {
}
/// Register a serialize function to access it from the JavaScript side
///
/// # Examples
///
/// ```
/// fn pretty_json(
/// cache: &std::collections::HashMap<String, serde_json::Value>,
/// ) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> {
/// Ok(serde_json::to_vec_pretty(&cache)?)
/// }
///
/// tauri::Builder::default()
/// .plugin(
/// tauri_plugin_store::Builder::default()
/// .register_serialize_fn("pretty-json".to_owned(), pretty_json)
/// .build(),
/// )
/// ```
pub fn register_serialize_fn(mut self, name: String, serialize_fn: SerializeFn) -> Self {
self.serialize_fns.insert(name, serialize_fn);
self