pub struct AimDbHandle { /* private fields */ }Expand description
Handle to the AimDB runtime thread.
Created by calling AimDb::attach(). Provides factory methods
for creating typed producers and consumers.
§Thread Safety
AimDbHandle is Send + Sync and can be shared across threads.
However, it should typically be owned by one thread, with only
the producers/consumers being cloned and shared.
§Resource Management
Call detach() explicitly to ensure clean shutdown. If the handle
is dropped without calling detach(), a warning will be logged
and an emergency shutdown will be attempted.
Implementations§
Source§impl AimDbHandle
impl AimDbHandle
Sourcepub fn producer<T>(&self) -> DbResult<SyncProducer<T>>
pub fn producer<T>(&self) -> DbResult<SyncProducer<T>>
Create a synchronous producer for type T.
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
let producer = handle.producer::<Temperature>()?;
producer.set(Temperature { celsius: 25.0 })?;Sourcepub fn consumer<T>(&self) -> DbResult<SyncConsumer<T>>
pub fn consumer<T>(&self) -> DbResult<SyncConsumer<T>>
Create a synchronous consumer for type T.
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
let consumer = handle.consumer::<Temperature>()?;
let temp = consumer.get()?;Sourcepub fn producer_with_capacity<T>(
&self,
capacity: usize,
) -> DbResult<SyncProducer<T>>
pub fn producer_with_capacity<T>( &self, capacity: usize, ) -> DbResult<SyncProducer<T>>
Create a synchronous producer with custom channel capacity.
Like producer() but allows specifying the channel buffer size.
Use this when you need different buffering characteristics for specific record types.
§Arguments
capacity: Channel buffer size (number of items that can be buffered)
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
// High-frequency sensor needs larger buffer
let producer = handle.producer_with_capacity::<HighFrequencySensor>(1000)?;
producer.set(HighFrequencySensor { value: 42.0 })?;Sourcepub fn consumer_with_capacity<T>(
&self,
capacity: usize,
) -> DbResult<SyncConsumer<T>>
pub fn consumer_with_capacity<T>( &self, capacity: usize, ) -> DbResult<SyncConsumer<T>>
Create a synchronous consumer with custom channel capacity.
Like consumer() but allows specifying the channel buffer size.
Use this when you need different buffering characteristics for specific record types.
§Arguments
capacity: Channel buffer size (number of items that can be buffered)
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
// Rare events need smaller buffer
let consumer = handle.consumer_with_capacity::<RareEvent>(10)?;
let event = consumer.get()?;