Redb Model
A derive macro for generating redb table definitions and DTO object
conversion methods/implementations.
Functionality
All functionality is implemented by the Model trait within. Decorating
a struct with #[derive(Model)] will define a redb::TableDefinition as
an associated constant for the type, with the specified fields as key/value
types, or tuples of types.
Specifying keys and values
Key(s) and value(s) are specified by decorating table fields with
#[entry(position(...))], passing either key or value to the inner field.
let user_key = ;
let user_value = ;
let user = from_values;
Specifying a table name
Table names default to the (case-sensitive) struct name. This can be overridden by decorating
the struct with #[model(name = "...")] attribute.
assert_eq!;
Type conversion
The generated implementation of the Model trait provides methods for
instantiating, borrowing and taking the key/value pairs of the model DTO.
See the Model trait for available methods. By default, #[derive(Model)]
will only generate an implementation of the Model trait. Decorating the
struct with #[model(impl_from)] will implement From<T>, mapping T to
the from_values(T) method.
#
let user_key = ;
let user_value = ;
let user: User = .into;
Implementation details
The following are notes
Unit type values
The unit type () must be passed if no value is defined.
#
#
let k = ;
let v = ; // `()` argument must be passed.
let e = from_values;
Variable Ordering
All composite key/value variables are combined as a tuple in the order they are defined.
The Model definition and redb::TableDefinition
The redb::TableDefinition uses 'static references of the variables types
Model, with the exception of String which uses a 'static string slice.
This is to ensure that calling as_values returns references suitable for
database calls.
License: MIT OR Apache-2.0