aimdb-core
Type-safe async data pipelines — one Rust codebase from MCU to cloud.
Overview
aimdb-core provides a type-safe, platform-agnostic data pipeline where the Rust type system is the schema and trait implementations define the behavior. Records flow through typed producer-consumer pipelines that compile unchanged for Tokio, Embassy and WASM.
Key Features:
- Type-Safe Records: Compile-time key + type pairs
- Runtime Agnostic: One codebase targets Tokio, Embassy and WASM via adapter pattern
- Producer-Consumer Pipelines: Source, tap and transform with typed buffers
- Pluggable Buffers: SPMC Ring, SingleLatest and Mailbox for different data flow patterns
- No-std Compatible: Core functionality works without standard library
- Derive Macros:
RecordKeyderive for compile-time safe record keys
Quick Start
Add to your Cargo.toml:
[]
= "1.0"
= "0.5" # or aimdb-embassy-adapter / aimdb-wasm-adapter
Define Records
Records consist of a key and a type. The RecordKey derive macro maps each variant to a unique string identifier:
/// Compile-time safe record keys.
/// A plain Rust struct — no framework traits required.
Producer and Consumer
Portable code uses R: Runtime — no platform imports needed:
/// Producer: reads a sensor and pushes typed values into AimDB.
async
/// Consumer: subscribes to the buffer and reacts to every new value.
async
Wire It Together
The builder ties key, type, buffer, producer and consumer together:
use ;
use BufferCfg;
use TokioAdapter;
use Arc;
async
Transforms
Records relate to each other in a DAG. A transform derives one record type from another:
builder.;
For complete working examples, see:
examples/tokio-mqtt-connector-demo— MQTT with Tokio runtimeexamples/embassy-mqtt-connector-demo— MQTT on embedded (RP2040)examples/sync-api-demo— Synchronous API usageexamples/remote-access-demo— AimX protocol server
Buffer Types
Choose the right buffer strategy for your use case:
SPMC Ring Buffer
Use for: High-frequency data streams with bounded memory
reg.buffer
- Bounded backlog for multiple consumers
- Fast producers can outrun slow consumers
- Oldest messages dropped on overflow
SingleLatest
Use for: State synchronization, configuration updates
reg.buffer
- Only stores newest value
- Intermediate updates collapsed
Mailbox
Use for: Commands and one-shot events
reg.buffer
- Single-slot with overwrite
- Latest command wins
Runtime Adapters
The only platform-specific code is choosing which runtime adapter to pass into the builder:
// On Linux / Cloud — Tokio
let runtime = new;
let mut builder = new.runtime;
// On Cortex-M4 — Embassy
let runtime = new;
let mut builder = new.runtime;
Everything else — records, keys, producers, consumers, transforms — stays identical across platforms.
Core depends on abstract traits from aimdb-executor:
RuntimeAdapter— Platform identificationSpawn— Task creationTimeOps— Clocks and sleepLogger— Structured output
Portable code receives a RuntimeContext<R> with two accessors:
ctx.time()→Time<R>with.sleep(),.now(),.secs(), etc.ctx.log()→Log<R>with.info(),.warn(), etc.
Available adapters:
- aimdb-tokio-adapter — Standard library / server environments
- aimdb-embassy-adapter — Embedded
no_std(Cortex-M) - aimdb-wasm-adapter — Browser / WASM targets
Connectors
Integrate with external systems:
- aimdb-mqtt-connector — MQTT for std (
rumqttc) and embedded (mountain-mqtt) - aimdb-knx-connector — KNX/IP for building automation
- aimdb-websocket-connector — WebSocket transport
See examples/tokio-mqtt-connector-demo for a complete connector integration.
Features
[]
= ["std", "alloc", "derive"]
= ["aimdb-derive"] # RecordKey derive macro
= ["alloc", "serde", ...] # Standard library support
= ["serde"] # Heap allocation for no_std
= ["dep:tracing"] # Structured logging (std + no_std)
= ["dep:defmt"] # Embedded logging via probe
= ["dep:metrics", "std"] # Performance metrics (requires std)
= ["std"] # Test helpers
Error Handling
All operations return DbResult<T> with DbError enum:
use ;
pub async
Common errors: RecordNotFound, ProducerFailed, ConsumerFailed, BufferError, ConnectorError.
Testing
# Run all tests
# Verify no_std compatibility
License
Apache 2.0 — see LICENSE.