indexed-struct
A Rust derive macro for creating indexed data structure with efficient query capabilities
Usage
use IndexedStruct;
The generated struct will look like this:
Macro Attributes
Struct Attributes
The IndexedStruct derive macro supports the following attributes on the struct itself:
#[indexed_struct(name = CustomName)]: Customize the name of the generated storage struct. By default, it appends "Store" to the original struct name.#[indexed_struct(key_type = KeyType)]: Customize the default key type used for the primary key. By default, no default is provided and you must specify it when using the store.
Example with struct attributes:
use IndexedStruct;
// This will generate a Pets<u32> struct with u32 as the default key type
Generated Methods
The macro generates various methods for efficient data access:
insert,remove: Basic CRUD operationsquery_{field}: Query by indexed field valuescontain_{field}: Check if indexed field value existsupdate_{field}: Update specific field valuesiter_by_{field}: Iterate ordered by indexed fieldrows_by_{field}: Get rows by indexed field
Field Attributes
| attr | type | default | description |
|---|---|---|---|
unique |
bool |
false |
Enforces value uniqueness constraint |
index |
enum |
"none" |
Index type for efficient queries ("none", "hash", "btree") |
skip |
bool |
false |
Ignore this field |
Index Types:
none: No index: Linear search through all records O(n)hash: Hash map index for O(1) average lookup time using hashbrown HashMapbtree: B-tree index for O(log n) lookup time with ordered iteration using std BTreeMap