百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

bevy_pkv

> 编程语言
开源

跨平台 (包括 WASM) 的持久性密钥值存储插件,用于 Rust 游戏/应用

181 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

跨平台 (包括 WASM) 的持久性密钥值存储插件,用于 Rust 游戏/应用

bevy_pkv

bevy_pkv is a cross-platform persistent key value store for rust apps.

Use it for storing things like settings, save games etc.

Currently, the Bevy dependency is optional, so it may be used in other games/apps as well.

Usage with Bevy

Add a store resource to your app

rust
# #[cfg(feature = "bevy")] { // ignore this line
use bevy::prelude::*;
use bevy_pkv::PkvStore;

fn main() {
App::new()
    .add_plugins(DefaultPlugins)
    .insert_resource(PkvStore::new("FooCompany", "BarGame"))
    // ...insert systems etc.
    .run();
}
# }

This will create or load a store in the appropriate location for your system, and make it available to bevy systems:

rust
fn setup(mut pkv: ResMut) {
    if let Ok(username) = pkv.get::("username") {
        info!("Welcome back {username}");
    } else {
        pkv.set_string("username", "alice")
            .expect("failed to store username");

        // alternatively, using the slightly less efficient generic api:
        pkv.set("username", &"alice".to_string())
            .expect("failed to store username");
    }
}

Using Custom Types

You can also store and retrieve your own types that implement serde::Serialize and Deserialize:

rust
#[derive(Serialize, Deserialize)]
struct User {
    name: String,
}

fn setup(mut pkv: ResMut) {
    if let Ok(user) = pkv.get::("user") {
        info!("Welcome back {}", user.name);
    } else {
        let user = User {
            name: "bob".to_string(),
        };
        pkv.set("user", &user).expect("failed to store user");
    }
}

Persistent Resources

For resources that should automatically persist when they change, use the convenient init_persistent_resource API:

rust
use bevy::prelude::*;
use bevy_pkv::prelude::*;
use serde::{Serialize, Deserialize};

#[derive(Resource, Serialize, Deserialize, Default)]
struct GameSettings {
    volume: f32,
    difficulty: u8,
}

App::new()
    .add_plugins(DefaultPlugins)
    .insert_resource(PkvStore::new("FooCompany", "BarGame"))
    .init_persistent_resource::()
    .run();

This automatically loads the resource from storage on startup and saves it whenever it changes!

See the examples for further usage

Usage without Bevy

Disable the default features when adding the dependency:

toml
bevy_pkv = {version = "0.9", default-features = false}

Implementation details

Native

redb and rmp_serde (MessagePack) is used for storage. It's creating a bevy_pkv.redb db in the appropriate application data directory for your system.

Alternatively, disable default-features and enable the rocksdb feature to use a RocksDB-based implementation or sled feature to use sled db.

Wasm

Window.localStorage and serde_json is used for storage. Perhaps IndexedDb and something else would have been a better choice, but its API is complicated, and I wanted a simple implementation and a simple synchronous API.

Bevy version support

The main branch targets the latest bevy release.

bevy bevy_pkv
0.19 0.16, main
0.18 0.15
0.17 0.14
0.16 0.13
0.15 0.12
0.14 0.11
0.13 0.10
0.12 0.9
0.11 0.8
0.10 0.7
0.9 0.6
0.8 0.5
0.7 0.2, 0.3, 0.4
0.6 0.1

License

MIT or Apache-2.0

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustbevybevy-pluginkey-valuelocalstorage

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言