pub struct AimDbInner { /* private fields */ }Expand description
Internal database state
Holds the registry of typed records with multiple index structures for efficient access patterns:
storages: Vec for O(1) hot-path access by RecordIdby_key: HashMap for O(1) lookup by stable RecordKeyby_type: HashMap for introspection (find all records of type T)types: Vec for runtime type validation during downcasts
Implementations§
Source§impl AimDbInner
impl AimDbInner
Sourcepub fn resolve<K: RecordKey>(&self, key: &K) -> Option<RecordId>
pub fn resolve<K: RecordKey>(&self, key: &K) -> Option<RecordId>
Resolve RecordKey to RecordId (control plane - O(1) average)
Sourcepub fn resolve_str(&self, name: &str) -> Option<RecordId>
pub fn resolve_str(&self, name: &str) -> Option<RecordId>
Resolve string to RecordId (convenience for remote access)
O(1) average thanks to Borrow<str> implementation on RecordKey.
Sourcepub fn storage(&self, id: RecordId) -> Option<&dyn AnyRecord>
pub fn storage(&self, id: RecordId) -> Option<&dyn AnyRecord>
Get storage by RecordId (hot path - O(1))
Sourcepub fn key_for(&self, id: RecordId) -> Option<&StringKey>
pub fn key_for(&self, id: RecordId) -> Option<&StringKey>
Get the StringKey for a given RecordId
Sourcepub fn records_of_type<T: 'static>(&self) -> &[RecordId]
pub fn records_of_type<T: 'static>(&self) -> &[RecordId]
Get all RecordIds for a type (introspection)
Sourcepub fn record_count(&self) -> usize
pub fn record_count(&self) -> usize
Get the number of registered records
Sourcepub fn get_typed_record_by_key<T, R>(
&self,
key: impl AsRef<str>,
) -> DbResult<&TypedRecord<T, R>>
pub fn get_typed_record_by_key<T, R>( &self, key: impl AsRef<str>, ) -> DbResult<&TypedRecord<T, R>>
Helper to get a typed record by RecordKey
This encapsulates the common pattern of:
- Resolving key to RecordId
- Validating TypeId matches
- Downcasting to the typed record
Sourcepub fn get_typed_record_by_id<T, R>(
&self,
id: RecordId,
) -> DbResult<&TypedRecord<T, R>>
pub fn get_typed_record_by_id<T, R>( &self, id: RecordId, ) -> DbResult<&TypedRecord<T, R>>
Helper to get a typed record by RecordId with type validation
Sourcepub fn list_records(&self) -> Vec<RecordMetadata>
pub fn list_records(&self) -> Vec<RecordMetadata>
Collects metadata for all registered records (std only)
Returns a vector of RecordMetadata for remote access introspection.
Available only when the std feature is enabled.
Sourcepub fn try_latest_as_json(&self, record_key: &str) -> Option<Value>
pub fn try_latest_as_json(&self, record_key: &str) -> Option<Value>
Sourcepub fn set_record_from_json(
&self,
record_key: &str,
json_value: Value,
) -> DbResult<()>
pub fn set_record_from_json( &self, record_key: &str, json_value: Value, ) -> DbResult<()>
Sets a record value from JSON (remote access API)
Deserializes the JSON value and writes it to the record’s buffer.
SAFETY: Enforces the “No Producer Override” rule:
- Only works for records with
producer_count == 0 - Returns error if the record has active producers
§Arguments
record_key- The record key (e.g., “config.app”)json_value- JSON representation of the value
§Returns
Ok(())- Successfully set the valueErr(DbError)- If record not found, has producers, or deserialization fails