AimDbHandle

Struct AimDbHandle 

Source
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

Source

pub fn producer<T>(&self, key: impl AsRef<str>) -> DbResult<SyncProducer<T>>
where T: Send + 'static + Debug + Clone,

Create a synchronous producer for type T.

§Arguments
  • key: The record key identifying this record instance
§Type Parameters
  • T: The record type, must implement TypedRecord
§Errors
  • DbError::RecordNotFound if type T was not registered
  • DbError::RuntimeShutdown if the runtime thread has stopped
§Example
let producer = handle.producer::<Temperature>("sensor::temp")?;
producer.set(Temperature { celsius: 25.0 })?;
Source

pub fn consumer<T>(&self, key: impl AsRef<str>) -> DbResult<SyncConsumer<T>>
where T: Send + Sync + 'static + Debug + Clone,

Create a synchronous consumer for type T.

§Arguments
  • key: The record key identifying this record instance
§Type Parameters
  • T: The record type, must implement TypedRecord
§Errors
  • DbError::RecordNotFound if type T was not registered
  • DbError::RuntimeShutdown if the runtime thread has stopped
§Example
let consumer = handle.consumer::<Temperature>("sensor::temp")?;
let temp = consumer.get()?;
Source

pub fn producer_with_capacity<T>( &self, key: impl AsRef<str>, capacity: usize, ) -> DbResult<SyncProducer<T>>
where T: Send + 'static + Debug + Clone,

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
  • key: The record key identifying this record instance
  • capacity: Channel buffer size (number of items that can be buffered)
§Type Parameters
  • T: The record type, must implement TypedRecord
§Errors
  • DbError::RecordNotFound if type T was not registered
  • DbError::RuntimeShutdown if the runtime thread has stopped
§Example
// High-frequency sensor needs larger buffer
let producer = handle.producer_with_capacity::<HighFrequencySensor>("sensor::high_freq", 1000)?;
producer.set(HighFrequencySensor { value: 42.0 })?;
Source

pub fn consumer_with_capacity<T>( &self, key: impl AsRef<str>, capacity: usize, ) -> DbResult<SyncConsumer<T>>
where T: Send + Sync + 'static + Debug + Clone,

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
  • key: The record key identifying this record instance
  • capacity: Channel buffer size (number of items that can be buffered)
§Type Parameters
  • T: The record type, must implement TypedRecord
§Errors
  • DbError::RecordNotFound if type T was not registered
  • DbError::RuntimeShutdown if the runtime thread has stopped
§Example
// Rare events need smaller buffer
let consumer = handle.consumer_with_capacity::<RareEvent>("events::rare", 10)?;
let event = consumer.get()?;
Source

pub fn detach(self) -> DbResult<()>

Gracefully shut down the runtime thread.

Signals the runtime to stop, waits for all pending operations to complete, then joins the thread. This is the preferred way to shut down.

§Errors
  • DbError::DetachFailed if shutdown fails or times out
§Example
handle.detach()?;
Source

pub fn detach_timeout(self, timeout: Duration) -> DbResult<()>

Gracefully shut down with a timeout.

Like detach(), but fails if shutdown takes longer than the specified duration.

§Arguments
  • timeout: Maximum time to wait for shutdown
§Errors
  • DbError::DetachFailed if shutdown fails or times out
§Example
handle.detach_timeout(Duration::from_secs(5))?;

Trait Implementations§

Source§

impl Drop for AimDbHandle

Source§

fn drop(&mut self)

Attempts graceful shutdown if detach() was not called.

Logs a warning and attempts shutdown with a 5-second timeout. If shutdown fails, the runtime thread may be left running.

Source§

impl Send for AimDbHandle

Source§

impl Sync for AimDbHandle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more