obj-derive 1.1.2

Procedural macros (#[derive(Document)]) for the obj embedded document database.
Documentation

obj-derive

The #[derive(Document)] procedural macro for obj.

crates.io

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-derive is an UNSTABLE implementation detail with no SemVer guarantee. Depend on obj-db instead 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:

#[derive(serde::Serialize, serde::Deserialize, obj::Document)]
#[obj(collection = "orders", version = 1)]
#[obj(index_composite(fields = ("region", "status"), name = "by_region_status"))]
struct Order {
    #[obj(index = unique)]
    email: String,
    #[obj(index)]
    region: String,
    #[obj(index = each)]   // multi-value index; field must be a Vec<...>
    tags: Vec<String>,
    status: String,
}
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.