Skip to main content

dice_rs/
lib.rs

1//! dice-rs — Core library for GoDice BLE dice.
2//!
3//! Provides domain types, BLE transport abstraction, and a high-level
4//! service API for scanning, connecting, and interacting with GoDice
5//! devices over Bluetooth Low Energy.
6//!
7//! # Quick Start
8//!
9//! ```no_run
10//! use dice_rs::{DiceManager, DiceEvent};
11//!
12//! #[tokio::main]
13//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
14//!     let manager = DiceManager::new().await?;
15//!     let devices = manager.scan().await?;
16//!
17//!     if devices.is_empty() {
18//!         println!("No GoDice devices found");
19//!         return Ok(());
20//!     }
21//!
22//!     let dice = manager.connect(&devices[0]).await?;
23//!     let mut receiver = dice.subscribe();
24//!     while let Ok(event) = receiver.recv().await {
25//!         match event {
26//!             DiceEvent::Stable { face, .. } => println!("Rolled: {face}"),
27//!             DiceEvent::RollStart => println!("Rolling..."),
28//!             DiceEvent::Disconnected => break,
29//!             _ => {}
30//!         }
31//!     }
32//!
33//!     Ok(())
34//! }
35//! ```
36
37pub mod ble;
38pub mod error;
39pub mod model;
40pub mod service;
41
42pub use model::acceleration::Acceleration;
43pub use model::battery_level::BatteryLevel;
44pub use model::charging_state::ChargingState;
45pub use model::dice::DiceColor;
46pub use model::dice::DiceType;
47pub use model::face::FaceValue;
48pub use model::led::LedColor;
49pub use service::dice::Dice;
50pub use service::dice::DiceDevice;
51pub use service::dice::DiceEvent;
52pub use service::manager::DiceManager;
53
54#[cfg(test)]
55mod tests {
56    #[test]
57    fn book_summary_has_all_chapters() {
58        let summary = include_str!("../../book/src/SUMMARY.md");
59        assert!(summary.contains("Introduction"));
60        assert!(summary.contains("Getting Started"));
61        assert!(summary.contains("Architecture"));
62        assert!(summary.contains("BLE Protocol"));
63        assert!(summary.contains("Scanning & Connecting"));
64        assert!(summary.contains("Dice Events"));
65        assert!(summary.contains("LED Control"));
66        assert!(summary.contains("Battery & Status"));
67        assert!(summary.contains("Calibration"));
68        assert!(summary.contains("CLI Tool"));
69        assert!(summary.contains("Controller"));
70        assert!(summary.contains("WebSocket Server"));
71        assert!(summary.contains("Platform Notes"));
72    }
73
74    #[test]
75    fn changelog_has_unreleased_section() {
76        let changelog = include_str!("../../CHANGELOG.md");
77        assert!(changelog.contains("## Unreleased"));
78        assert!(changelog.contains("### Added"));
79        assert!(changelog.contains("### Changed"));
80        assert!(changelog.contains("### Fixed"));
81    }
82}