For anyone interested in how my current solution looks like, it can be found here:
mmtkvdb::storablemmtkvdb::owning_pointer-
mmtkbdb::helpers::IsType(
private helper trait)
Not sure if it's particularly beautiful, but it seems to do what I want:
- In standard cases, only one trait (
Storable) needs to be implemented to allow using a type for keys or values in databases ⇒ "easy"
- Types which do not require alignment, such as
[u8], don't need to be copied when reading them from a database ⇒ fast when reading
) - Types which require alignment are supported by returning a weird smart-pointer (
owning_pointer::Owned), which holds the pointed-to value (basically aCowwhich is alwaysCow::Owned) ⇒ known at compile-time
-
Automatic implementations of
Storablefor tuples(T1, T2, …)are provided where allTn's implementBorrowStorableand all but the last element have aBorrowStorable::Storedtype which has a constant size when being stored ⇒ handy
- Storing values can be done by referencing the value or, in case of tuples, providing a tuple of references to the inner values (see doc of
StorableRef), avoiding to create an intermediate tuple when references to the inner values exist ⇒ not unnecessary slow when writing
One problem for sure, however, is overall complexity.
![]()