obj-derive
The
#[derive(Document)]procedural macro forobj.
Part of obj — the embedded document
database. obj-derive provides the #[derive(Document)] macro that
generates a type's collection binding, schema, and secondary-index
descriptors.
Internal crate — not for direct use.
obj-deriveis an UNSTABLE implementation detail with no SemVer guarantee. Depend onobj-dbinstead and use the re-exported derive (obj::Document); it is published only so the public crate can resolve it.
What it generates
#[derive(Document)] reads #[obj(...)] attributes and emits the
Document impl — the collection name, schema version, and index set:
| Attribute | Level | Effect |
|---|---|---|
collection = "..." |
struct | Override the collection name (defaults to the type). |
version = N |
struct | Set the schema version (defaults to 1). |
index_composite(fields = (...), name = "...") |
struct | Composite index over ≥ 2 fields (name optional). |
index |
field | Standard secondary index on the field. |
index = unique |
field | Unique secondary index on the field. |
index = each |
field | Multi-value index over each element of a Vec field. |
name = "..." |
field | Override an index's default name (the field name). |
A history(v1 = OldType, ...) struct attribute registers historical
schemas for lazy per-document migration.
The encoding is positional and schema-driven — no field names in the
bytes — so the generated codec round-trips byte-identically with the
Python @obj.document writer for the same logical schema.
License
Dual-licensed under MIT or Apache 2.0, at your option.