For anyone interested in how my current solution looks like, it can be found here:
mmtkvdb::storable
mmtkvdb::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 aCow
which is alwaysCow::Owned
) ⇒ known at compile-time -
Automatic implementations of
Storable
for tuples(T1, T2, …)
are provided where allT
n's implementBorrowStorable
and all but the last element have aBorrowStorable::Stored
type 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.