IndexedStruct

Derive Macro IndexedStruct 

Source
#[derive(IndexedStruct)]
{
    // Attributes available to this derive:
    #[indexed_struct]
}
Expand description

A derive macro that generates a store struct with index capabilities for the fields of a struct.

This macro generates a new struct with a Store suffix (configurable with the name attribute) that can store instances of the original struct with efficient indexing and querying capabilities.

§Usage

The macro can be applied to a struct with optional attributes on the struct itself and its fields:

  • On the struct:

    • name = CustomStoreName: Specify a custom name for the generated store struct
    • key_type = Type: Specify the default key type for the store (defaults to the type parameter)
  • On fields:

    • skip: Skip this field in the generated store
    • unique: Enforce uniqueness constraint on this field
    • index = "hash": Create a hash-based index for this field
    • index = "btree": Create a B-tree based index for this field (ordered iteration)

§Example

use indexed_struct::IndexedStruct;

#[derive(IndexedStruct)]
struct Person {
    id: u32,
    #[indexed_struct(unique, index = "hash")]
    email: String,
    #[indexed_struct(index = "btree")]
    age: u32,
    #[indexed_struct(skip)]
    secret: String,
}

// This generates a PersonStore struct with methods for inserting, querying, and managing Person instances