Skip to main content

pamoja_core/
lib.rs

1//! Core abstractions for the pamoja device SDK.
2//!
3//! This crate defines the traits that every capability crate (for example
4//! `pamoja-mqtt`, `pamoja-serial`, or `pamoja-ros2`) implements. The
5//! core is protocol-agnostic: it models devices, sensors, actuators, transports,
6//! durable storage, and an event bus, and leaves concrete protocol support to the
7//! capability crates so that an application depends only on what it uses.
8//!
9//! The primary abstractions are:
10//!
11//! - [`Device`] - a connectable physical or virtual device.
12//! - [`Sensor`] - a source of typed readings.
13//! - [`Actuator`] - a sink for typed commands.
14//! - [`Telemetry`] - a stream of telemetry frames.
15//! - [`Transport`] - a bidirectional byte transport.
16//! - [`Store`] - a durable store-and-forward queue.
17//! - [`EventBus`] - a typed publish/subscribe channel.
18//! - [`Error`] and [`Result`] - the shared error model.
19//!
20//! # Examples
21//!
22//! Implementing [`Sensor`] for a temperature probe:
23//!
24//! ```
25//! use pamoja_core::{Result, Sensor};
26//!
27//! struct Thermometer {
28//!     celsius: f32,
29//! }
30//!
31//! impl Sensor for Thermometer {
32//!     type Reading = f32;
33//!
34//!     async fn read(&mut self) -> Result<Self::Reading> {
35//!         Ok(self.celsius)
36//!     }
37//! }
38//!
39//! let _probe = Thermometer { celsius: 20.5 };
40//! ```
41
42// The core is `no_std` unless the default `std` feature is on, so it fits a
43// microcontroller. The owned types it needs (`String`, `Vec`) come from `alloc`.
44#![cfg_attr(not(feature = "std"), no_std)]
45// The public traits use `async fn`, which is intentional for this statically
46// dispatched SDK; the associated lint is therefore allowed crate-wide.
47#![allow(async_fn_in_trait)]
48
49extern crate alloc;
50
51pub mod bus;
52pub mod device;
53pub mod error;
54pub mod store;
55pub mod transport;
56
57pub use bus::EventBus;
58pub use device::{Actuator, Device, Sensor, Telemetry};
59pub use error::{Error, Result};
60pub use store::Store;
61pub use transport::Transport;