This derive macro helps to define documents which can be managed using persistent storages like LEDB.
The LEDB is an attempt to implement simple but efficient, lightweight but powerful document storage.
The abbreviation LEDB may be treated as an Lightweight Embedded DB, also Low End DB, also Literium Engine DB, also LitE DB, and so on.
```rust use serde::{Serialize, Deserialize}; use ledb::{Document};
struct MyDoc {
// define optional primary key field
#[document(primary)]
id: Option
struct MetaData {
// define index field
#[document(index)]
keywords: Vec
This automatically generate Document
traits like so:
```rust impl Document for MyDoc { // declare primary key field name fn primary_field() -> Identifier { "id".into() }
// declare other key fields for index
fn key_fields() -> KeyFields {
KeyFields::new()
// add key fields of document
.with_field(("title", String::key_type(), IndexKind::Unique))
.with_field(("tag", String::key_type(), IndexKind::Index))
.with_field(("timestamp", u32::key_type(), IndexKind::Unique))
// add key fields from nested document
.with_fields(MetaData::key_fields().with_parent("meta"))
}
}
impl Document for MetaData { // declare key fields for index fn keyfields() -> KeyFields { KeyFields::new() // add key fields of document .withfield(("keywords", KeyType::String, IndexKind::Index)) } } ```