#serialization #database #storage #break #content-addressable #derive #casserole

macro casserole-derive

Break and serialize values into content-addressable storage

2 unstable releases

0.2.0 Aug 4, 2021
0.1.0 Jul 20, 2021

#28 in #content-addressable

Download history 121/week @ 2024-03-31 72/week @ 2024-04-07 49/week @ 2024-04-14 115/week @ 2024-04-21 162/week @ 2024-04-28 88/week @ 2024-05-05 88/week @ 2024-05-12 204/week @ 2024-05-19 48/week @ 2024-05-26 114/week @ 2024-06-02 51/week @ 2024-06-09 38/week @ 2024-06-16 99/week @ 2024-06-23 51/week @ 2024-06-30 60/week @ 2024-07-07 114/week @ 2024-07-14

328 downloads per month
Used in casserole

MIT/Apache

25KB
564 lines

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);

Dependencies

~1.5MB
~36K SLoC