Skip to main content

Module record_id

Module record_id 

Source
Expand description

Record identification types for stable, O(1) lookups

This module provides key types for record identification:

  • RecordKey: A trait for type-safe record identifiers
  • StringKey: Default string-based key implementation
  • RecordId: An internal index for O(1) hot-path lookups

§Design Rationale

AimDB separates logical identity (RecordKey) from physical identity (RecordId):

  • RecordKey is a trait that can be implemented by user-defined enums for compile-time checked keys, or use the default StringKey for string-based keys.

  • RecordId is the hot-path identifier used internally for O(1) Vec indexing during produce/consume operations.

§Examples

§StringKey (default, edge/cloud)

use aimdb_core::record_id::StringKey;

// Static keys (zero allocation, preferred)
let key: StringKey = "sensors.temperature".into();
assert!(key.is_static());

// Dynamic keys (for runtime-generated names)
let tenant_id = "acme";
let key = StringKey::intern(format!("tenant.{}.sensors", tenant_id));
assert!(!key.is_static());

§Enum Keys (compile-time safe, embedded)

Illustrative (not compiled: the derive macro lives in aimdb-derive, behind the optional derive feature):

ⓘ
use aimdb_derive::RecordKey;

#[derive(RecordKey, Clone, Copy, PartialEq, Eq)]
pub enum AppKey {
    #[key = "temp.indoor"]
    TempIndoor,
    #[key = "temp.outdoor"]
    TempOutdoor,
}

// Compile-time typo detection!
builder.configure::<Temperature>(AppKey::TempIndoor, |reg| { /* … */ });

Structs§

RecordId
Internal record identifier (index into storage Vec)
StringKey
Default string-based record key

Traits§

RecordKey
Trait for record key types

Derive Macros§

RecordKey
Derive the RecordKey trait for an enum