RecordKey

Derive Macro RecordKey 

Source
#[derive(RecordKey)]
{
    // Attributes available to this derive:
    #[key]
    #[key_prefix]
    #[link_address]
}
Expand description

Derive the RecordKey trait for an enum

Each variant must have a #[key = "..."] attribute specifying its string key. Optionally, the enum can have a #[key_prefix = "..."] attribute to prepend a common prefix to all keys.

§Connector Metadata

Variants can have a #[link_address = "..."] attribute to associate a connector URL/address with the key (MQTT topics, KNX group addresses, etc.):

§Example

// Note: Hash is auto-generated to satisfy the Borrow<str> contract
#[derive(RecordKey, Clone, Copy, PartialEq, Eq)]
#[key_prefix = "sensors."]
pub enum SensorKey {
    #[key = "temp"]           // → "sensors.temp"
    #[link_address = "mqtt://sensors/temp/indoor"]
    Temperature,

    #[key = "humid"]          // → "sensors.humid"
    #[link_address = "knx://9/0/1"]
    Humidity,
}

§Generated Code

The macro generates:

  • impl aimdb_core::RecordKey for YourEnum with as_str() and link_address() methods
  • impl core::borrow::Borrow<str> for YourEnum for O(1) HashMap lookups
  • impl core::hash::Hash for YourEnum that hashes the string key (required by Borrow contract)