Expand description
Traits allowing to use types as key or value
Any type that implements Storable
can be used as a key or value in a
Db
. Implementation is unsafe
and must be correct and not
change between (re-)opening environments.
Types that have a fixed-length byte representation should additionally
implement StorableConstBytesLen
.
When values are retrieved from a database, e.g. with
Txn::get
, they are returned as a pointer of type
Storable::AlignedRef
, which may be an ordinary shared reference or a
smart-pointer (e.g. Owned
) holding a copy for the purpose of memory
alignment. These references may be used directly (via
dereferencing) or be converted into an owned value using
GenericCow::into_owned
(alternatively, method
Txn::get_owned
may be used to retrieve an owned
value, which isn’t provided for the cursor methods though).
When storing values, e.g. with Txn::put
, a reference
to the Storable
value must be provided. Alternatively, a reference-like
value can be provided if it implements StorableRef
. For example,
(&'a i32, &'a str)
implements StorableRef<'a, (i32, String)>
and may be
passed instead of &'a (i32, String)
to avoid unnecessary cloning to
construct the tuple.
Traits
Types that can be borrowed as a type that is Storable
Types that can be stored
Types that can be stored with a fixed-length byte representation
Reference-like types which can be used to store a Storable
type
Storable
types where the owning type of the
pointed-to restored value is a certain type