buswatch_types/
lib.rs

1#![warn(missing_docs)]
2
3//! # buswatch-types
4//!
5//! Core types for message bus observability. This crate defines the universal
6//! schema that any message bus system can use to emit metrics consumable by
7//! buswatch and other monitoring tools.
8//!
9//! ## Design Goals
10//!
11//! - **Zero required dependencies**: Core types work without any serialization framework
12//! - **Optional serialization**: Enable `serde` and/or `minicbor` features as needed
13//! - **Protocol agnostic**: Works with RabbitMQ, Kafka, NATS, Redis Streams, or custom buses
14//! - **Versioned schema**: Snapshots include version info for forward compatibility
15//! - **Ergonomic builders**: Fluent API for constructing snapshots
16//!
17//! ## Features
18//!
19//! - `std` (default): Standard library support
20//! - `serde`: JSON/MessagePack/etc. serialization via serde
21//! - `minicbor`: Compact binary serialization via CBOR
22//! - `all`: Enable all serialization formats
23//!
24//! ## Example
25//!
26//! ```rust
27//! use buswatch_types::{Snapshot, ModuleMetrics, ReadMetrics, WriteMetrics};
28//! use std::time::Duration;
29//!
30//! // Build a snapshot using the builder pattern
31//! let snapshot = Snapshot::builder()
32//!     .module("order-processor", |m| {
33//!         m.read("orders.new", |r| {
34//!             r.count(1500)
35//!              .backlog(23)
36//!              .pending(Duration::from_millis(150))
37//!         })
38//!         .write("orders.processed", |w| {
39//!             w.count(1497)
40//!         })
41//!     })
42//!     .module("notification-sender", |m| {
43//!         m.read("orders.processed", |r| r.count(1450).backlog(47))
44//!     })
45//!     .build();
46//!
47//! assert_eq!(snapshot.modules.len(), 2);
48//! ```
49//!
50//! ## Schema Version
51//!
52//! The current schema version is **1**. The version is included in serialized
53//! snapshots to allow consumers to handle format evolution gracefully.
54
55#![cfg_attr(not(feature = "std"), no_std)]
56
57extern crate alloc;
58
59mod duration;
60mod metrics;
61mod snapshot;
62mod version;
63
64pub use duration::*;
65pub use metrics::*;
66pub use snapshot::*;
67pub use version::*;
68
69/// Current schema version.
70///
71/// Increment this when making breaking changes to the snapshot format.
72/// Consumers should check this version and handle older formats appropriately.
73pub const SCHEMA_VERSION: u32 = 1;