Crates.io | savefile |
lib.rs | savefile |
version | |
source | src |
created_at | 2018-03-01 12:29:40.541237 |
updated_at | 2024-12-01 08:15:22.632579 |
description | Simple, convenient, fast, versioned, binary serialization/deserialization library. |
homepage | https://github.com/avl/savefile/ |
repository | https://github.com/avl/savefile |
max_upload_size | |
id | 53315 |
Cargo.toml error: | TOML parse error at line 20, column 1 | 20 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Having trouble with new version 0.17? - See upgrade guide further down in this document!
Savefile is a crate to effortlessly serialize rust structs and enums. It uses an efficient binary format. It can serialize to anything implementing the Write trait, and then deserialize from anything implementing the Read trait. This means that savefile can be used to easily save in-memory data structures to disk for persistent storage.
Docs: https://docs.rs/savefile/latest/savefile/
Savefile-Abi is a related crate, which allows publishing forward- and backward compatible shared libraries, written in rust, to be used as binary plugins in rust-programs.
Docs: https://docs.rs/savefile-abi/latest/
Cargo.toml:
savefile = "0.18"
savefile-derive = "0.18"
main.rs:
extern crate savefile;
use savefile::prelude::*;
#[macro_use]
extern crate savefile_derive;
#[derive(Savefile)]
struct Player {
name : String,
strength : u32,
inventory : Vec<String>,
}
fn save_player(player:&Player) {
save_file("save.bin", 0, player).unwrap();
}
fn load_player() -> Player {
load_file("save.bin", 0).unwrap()
}
fn main() {
let player = Player { name: "Steve".to_string(), strength: 42,
inventory: vec!(
"wallet".to_string(),
"car keys".to_string(),
"glasses".to_string())};
save_player(&player);
let reloaded_player = load_player();
assert_eq!(reloaded_player.name,"Steve".to_string());
}
The savefile docs are available at: https://docs.rs/savefile/latest/savefile/
See the changelog.
Features savefile has:
Features savefile does not have:
Features savefile does not have, and will not have:
Common errors:
MyStuff: WithSchema
is not satisfied"This probably means you've forgotten to derive the Savefile-traits. Add a #[derive(Savefile)]
.
ReprC
is not implementedThis one is easy. ReprC
has been renamed to Packed
. Just change to Packed
and things should work.
Savefile is licensed under either of
at your option.
MIT License text:
Copyright 2018 Anders Musikka
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.