aimdb_tokio_adapter/
lib.rs

1//! Tokio Adapter for AimDB
2//!
3//! This crate provides Tokio-specific extensions for AimDB, enabling the database
4//! to run on standard library environments using the Tokio async runtime.
5//!
6//! # Features
7//!
8//! - **Tokio Integration**: Seamless integration with Tokio async executor
9//! - **Time Support**: Timestamp, sleep, and delayed task capabilities with `tokio::time`
10//! - **Error Handling**: Tokio-specific error conversions and handling
11//! - **Std Compatible**: Designed for environments with full standard library
12//!
13//! # Architecture
14//!
15//! Tokio is a std async runtime, so this adapter is designed for standard
16//! environments and works with the std version of aimdb-core by default.
17//!
18//! The adapter extends AimDB's core functionality without requiring tokio
19//! dependencies in the core crate. It provides:
20//!
21//!
22//! - **Runtime Module**: Core async task spawning with `RuntimeAdapter`
23//! - **Time Module**: Time-related capabilities like timestamps and sleep
24//! - **Error Module**: Runtime error constructors and conversions
25//! - Rich error descriptions leveraging std formatting capabilities
26//!
27//! See the repository examples for complete usage patterns.
28
29// Tokio adapter always requires std
30#[cfg(not(feature = "std"))]
31compile_error!("tokio-adapter requires the std feature");
32
33pub mod buffer;
34pub mod connector;
35pub mod error;
36pub mod runtime;
37pub mod time;
38
39pub use buffer::TokioBuffer;
40pub use error::TokioErrorSupport;
41
42#[cfg(feature = "tokio-runtime")]
43pub use runtime::TokioAdapter;
44
45/// Type alias for Tokio database
46///
47/// This provides a convenient type for working with databases on the Tokio runtime.
48/// Most users should use `AimDbBuilder` directly to create databases.
49#[cfg(feature = "tokio-runtime")]
50pub type TokioDatabase = aimdb_core::Database<TokioAdapter>;
51
52// Generate extension trait for Tokio adapter using the macro
53aimdb_core::impl_record_registrar_ext! {
54    TokioRecordRegistrarExt,
55    TokioAdapter,
56    TokioBuffer,
57    "tokio-runtime",
58    |cfg| TokioBuffer::<T>::new(cfg)
59}