#save #save-load #desktop #location #configuration #web #cross-platform

gestalt

跨平台桌面和Web之间的配置和数据保存

1个不稳定版本

0.1.0 2019年10月20日

#1621 in 编码

Download history 84/week @ 2024-04-08 111/week @ 2024-04-15 103/week @ 2024-04-22 94/week @ 2024-04-29 88/week @ 2024-05-06 90/week @ 2024-05-13 85/week @ 2024-05-20 85/week @ 2024-05-27 76/week @ 2024-06-03 50/week @ 2024-06-10 91/week @ 2024-06-17 88/week @ 2024-06-24 34/week @ 2024-07-08 97/week @ 2024-07-15 71/week @ 2024-07-22

每月213次下载
用于 3 个crate(通过 quicksilver

MIT/Apache

16KB
260

gestalt

跨平台桌面和Web之间的配置和数据保存

在桌面端,保存由文件系统和API支持,并使用特定平台的数据位置。在Web端,保存由LocalStorage浏览器API支持。作为最终用户,您只需要关心您想要保存到哪个 Location

  • Cache,它是短暂的,可能不会在程序运行之间持久化
  • Config,用于存储长期配置
  • Data,用于存储长期的大型数据块。

要保存和加载数据

use gestalt::{Location, save, load};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Player {
name: String,
score: u32
}

let player1 = Player { name: "Bob".to_string(), score: 21 };
save(Location::Cache, "mygame", "player1", &player1).expect("Could not save Player 1");

let player2 = Player { name: "Alice".to_string(), score: 200 };
save(Location::Cache, "mygame", "player2", &player2).expect("Could not save Player 2");

// Now reload.
let player1 = load::<Player>(Location::Cache, "mygame", "player1").expect("Could not load Player 1");
let player2 = load::<Player>(Location::Cache, "mygame", "player2").expect("Could not load Player 2");

依赖项

~0.7–4MB
~81K SLoC