| Crates.io | aimdb-derive |
| lib.rs | aimdb-derive |
| version | 0.1.0 |
| created_at | 2025-12-25 20:46:25.032661+00 |
| updated_at | 2025-12-25 20:46:25.032661+00 |
| description | Derive macros for AimDB record key types |
| homepage | |
| repository | https://github.com/aimdb-dev/aimdb |
| max_upload_size | |
| id | 2004928 |
| size | 13,528 |
Derive macros for AimDB record key types.
This crate provides the #[derive(RecordKey)] macro for defining compile-time
checked record keys in AimDB. This is especially useful for embedded systems
where typos in string keys would cause runtime failures.
use aimdb_derive::RecordKey;
#[derive(RecordKey, Clone, Copy, PartialEq, Eq, Debug)]
pub enum AppKey {
#[key = "temp.indoor"]
TempIndoor,
#[key = "temp.outdoor"]
TempOutdoor,
#[key = "light.main"]
LightMain,
}
// Now use in AimDB:
let producer = db.producer::<Temperature>(AppKey::TempIndoor);
#[key = "..."] (required on variants)Specifies the string key for a variant. This is the value returned by as_str().
#[key_prefix = "..."] (optional on enum)Prepends a prefix to all variant keys:
#[derive(RecordKey, Clone, Copy, PartialEq, Eq)]
#[key_prefix = "sensors."]
pub enum SensorKey {
#[key = "temp"] // → "sensors.temp"
Temp,
#[key = "humid"] // → "sensors.humid"
Humidity,
}
The macro generates:
impl RecordKey for YourEnum with as_str() methodimpl Borrow<str> for YourEnum for O(1) HashMap lookupsThis crate is fully no_std compatible. The generated code uses only
core::borrow::Borrow, not std::borrow::Borrow.
Apache-2.0