pub struct Database<A: RuntimeAdapter + Spawn + 'static> { /* private fields */ }Expand description
AimDB Database implementation
Unified database combining runtime adapter management with type-safe record
registration and producer-consumer patterns. See examples/ for usage patterns.
This is a thin wrapper around AimDb<R> that adds adapter-specific functionality.
Most users should use AimDbBuilder directly to create databases.
Implementations§
Source§impl<A: RuntimeAdapter + Spawn + 'static> Database<A>
impl<A: RuntimeAdapter + Spawn + 'static> Database<A>
Sourcepub fn new(adapter: A, aimdb: AimDb<A>) -> DbResult<Self>
pub fn new(adapter: A, aimdb: AimDb<A>) -> DbResult<Self>
Creates a new database from adapter and AimDb
§Arguments
adapter- The runtime adapteraimdb- The configured AimDb instance
Most users should use AimDbBuilder directly instead of this constructor.
Sourcepub fn subscribe<T>(
&self,
key: impl AsRef<str>,
) -> DbResult<Box<dyn BufferReader<T> + Send>>
pub fn subscribe<T>( &self, key: impl AsRef<str>, ) -> DbResult<Box<dyn BufferReader<T> + Send>>
Subscribes to a record by key
Creates a subscription to the configured buffer for the given record key. Returns a boxed reader for receiving values asynchronously.
§Example
ⓘ
let mut reader = db.subscribe::<SensorData>("sensor.temp")?;
loop {
match reader.recv().await {
Ok(data) => println!("Received: {:?}", data),
Err(e) => {
eprintln!("Error: {:?}", e);
break;
}
}
}Source§impl<A> Database<A>where
A: RuntimeAdapter + Spawn,
impl<A> Database<A>where
A: RuntimeAdapter + Spawn,
Sourcepub fn spawn<F>(&self, future: F) -> DbResult<()>
pub fn spawn<F>(&self, future: F) -> DbResult<()>
Spawns a service on the database’s runtime
§Example
ⓘ
async fn my_service<R: Runtime>(ctx: aimdb_core::RuntimeContext<R>) -> aimdb_core::DbResult<()> {
// Service implementation
Ok(())
}
let ctx = db.context();
db.spawn(async move {
if let Err(e) = my_service(ctx).await {
eprintln!("Service error: {:?}", e);
}
})?;Auto Trait Implementations§
impl<A> Freeze for Database<A>where
A: Freeze,
impl<A> !RefUnwindSafe for Database<A>
impl<A> Send for Database<A>
impl<A> Sync for Database<A>
impl<A> Unpin for Database<A>where
A: Unpin,
impl<A> !UnwindSafe for Database<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more