oxedyne/fe2o3/fe2o3_bot/src/lib.rs
1.4 KiB, 7 runs
created by r1870400018:42, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! Thread worker abstraction library for building concurrent applications. |
| 2 | //! |
| 3 | //! This crate provides the [`Bot`] trait and supporting types for implementing worker threads |
| 4 | //! (called "bots") with consistent error handling, communication, and termination semantics. |
| 5 | //! |
| 6 | //! # Key Features |
| 7 | //! |
| 8 | //! - Identity and labeling via the [`NumIdDat`] type |
| 9 | //! - Message passing through typed channels using [`BotMsg`] |
| 10 | //! - Error counting with configurable warning thresholds |
| 11 | //! - Graceful shutdown via [`Sentinel`]s |
| 12 | //! - Common patterns for handling communication errors |
| 13 | //! |
| 14 | //! # Example |
| 15 | //! |
| 16 | //! ```rust,no_run |
| 17 | //! use oxedyne_fe2o3_bot::{Bot, BotMsg}; |
| 18 | //! use oxedyne_fe2o3_core::prelude::*; |
| 19 | //! use oxedyne_fe2o3_jdat::id::NumIdDat; |
| 20 | //! |
| 21 | //! // Define bot message type |
| 22 | //! #[derive(Clone, Debug)] |
| 23 | //! enum WorkerMsg { |
| 24 | //! Process(String), |
| 25 | //! Shutdown, |
| 26 | //! } |
| 27 | //! |
| 28 | //! impl BotMsg<ErrTag> for WorkerMsg {} |
| 29 | //! |
| 30 | //! // Implement bot with u8 ID |
| 31 | //! struct Worker { |
| 32 | //! id: u8, |
| 33 | //! // ... other fields |
| 34 | //! } |
| 35 | //! |
| 36 | //! impl Bot<1, u8, WorkerMsg> for Worker { |
| 37 | //! fn id(&self) -> u8 { self.id } |
| 38 | //! // ... implement other required methods |
| 39 | //! } |
| 40 | //! ``` |
| 41 | //! |
| 42 | //! The crate avoids use of `unsafe` code and provides comprehensive error handling patterns. |
| 43 | //! |
| 44 | #![forbid(unsafe_code)] |
| 45 | #![allow(dead_code)] |
| 46 | |
| 47 | pub mod bot; |
| 48 | pub mod handles; |
| 49 | //pub mod id; |
| 50 | pub mod msg; |
| 51 | |
| 52 | pub use bot::Bot; |