Skip to main content

ObjectStore

Derive Macro ObjectStore 

Source
#[derive(ObjectStore)]
{
    // Attributes available to this derive:
    #[store]
    #[index]
}
Expand description

Derive the ObjectStore trait for a struct.

Generates an implementation of ObjectStore::store_def() based on the struct’s #[store(...)] container attribute and #[index(...)] field attributes.

§Container Attribute

#[store(key_path = "...")] — required. Specifies the primary key field path. Options:

  • name = "..." — override the store name (defaults to the struct name)
  • auto_increment — enable auto-increment primary keys
#[derive(ObjectStore)]
#[store(key_path = "id", auto_increment)]
struct Log { ... }

§Field Attributes

#[index(...)] on a field creates a secondary index. Accepted options:

  • unique — create a unique index
  • name = "..." — custom index name (defaults to the field name)
#[derive(ObjectStore)]
#[store(key_path = "id")]
struct User {
    #[index(unique)]
    email: String,
    #[index]
    age: u32,
    city: String,          // no index
}