Crates.io | casserole |
lib.rs | casserole |
version | 0.2.0 |
source | src |
created_at | 2021-07-20 20:00:01.175328 |
updated_at | 2021-08-04 03:35:45.728573 |
description | Break and serialize values into content-addressable storage |
homepage | https://github.com/da-x/casserole |
repository | https://github.com/da-x/casserole |
max_upload_size | |
id | 425282 |
size | 39,261 |
The casserole
crate provides a custom derive and a trait to perform
break-down serialization and de-serialization of Rust types into stores.
The most common use case is to break down large objects to be stored in content-addressable storage, like in a Git database. Hence the name 'CAS-ser-role'.
The trait which Casserole auto-derives generates smaller types that contain
references to keys instead of the original data. For example HashMap<String, BigValue>
is replaced with HashMap<String, S::Key>
where S
is a type
parameter to a user-provided storage engine. In addition, fields on which the
store
attribute is given e.g. #[casserole(store)]
, are also replaced with
S::Key
.
For example:
/// Example Tree to be stored in the database
#[derive(Casserole)]
struct Node {
header: String,
// Tells that 'map' is replaced by a database key in the type returned from
// the 'casserole' trait method. The 'decasserole' trait method will do the
// reverse, restoring it from the database.
#[casserole(store)]
map: BTreeMap<String, Node>,
}
Basic usage demonstration (given big_value
as a large value to work with):
// Create a our serde-ready type for the root. `stored_root` is our unique
// representation for `big_value`, but it is very small, like a Git hash.
let stored_root = big_value.casserole(&mut store).unwrap();
// <...do other stuff...>
// Restore the origin value from the database
let restored_big_value = Casserole::decasserole(&stored, &mut store).unwrap();
assert_eq!(restored_big_value, big_value);