Crates.io | savefile-derive |
lib.rs | savefile-derive |
version | 0.18.4 |
source | src |
created_at | 2018-03-01 12:28:39.766094 |
updated_at | 2024-11-04 20:34:10.695328 |
description | Custom derive macros for savefile crate - simple, convenient, fast, versioned, binary serialization/deserialization library. |
homepage | |
repository | https://github.com/avl/savefile |
max_upload_size | |
id | 53314 |
size | 227,217 |
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.