canlink_hal/queue/mod.rs
1//! Queue management module (FR-011, FR-017)
2//!
3//! This module provides bounded queue functionality with configurable
4//! overflow policies for CAN message handling.
5//!
6//! # Overview
7//!
8//! The queue module provides a bounded message queue that prevents unbounded
9//! memory growth when messages arrive faster than they can be processed.
10//!
11//! # Components
12//!
13//! - [`BoundedQueue`]: A fixed-capacity queue for CAN messages
14//! - [`QueueOverflowPolicy`]: Strategy for handling queue overflow
15//! - [`QueueStats`]: Statistics about queue operations
16//! - [`QueueConfig`]: Configuration loaded from TOML files
17//!
18//! # Overflow Policies
19//!
20//! When the queue is full, one of these policies is applied:
21//!
22//! - [`QueueOverflowPolicy::DropOldest`]: Remove the oldest message (default)
23//! - [`QueueOverflowPolicy::DropNewest`]: Reject the new message
24//! - [`QueueOverflowPolicy::Block`]: Block until space is available (with timeout)
25//!
26//! # Example
27//!
28//! ```rust
29//! use canlink_hal::queue::{BoundedQueue, QueueOverflowPolicy};
30//! use canlink_hal::CanMessage;
31//!
32//! // Create a queue with capacity 100 and DropOldest policy
33//! let mut queue = BoundedQueue::with_policy(100, QueueOverflowPolicy::DropOldest);
34//!
35//! // Push messages
36//! let msg = CanMessage::new_standard(0x123, &[1, 2, 3]).unwrap();
37//! queue.push(msg).unwrap();
38//!
39//! // Pop messages
40//! if let Some(msg) = queue.pop() {
41//! println!("Received: {:?}", msg);
42//! }
43//!
44//! // Check statistics
45//! let stats = queue.stats();
46//! println!("Enqueued: {}, Dequeued: {}, Dropped: {}",
47//! stats.enqueued, stats.dequeued, stats.dropped);
48//! ```
49//!
50//! # Thread Safety
51//!
52//! `BoundedQueue` is not thread-safe by itself. For multi-threaded access,
53//! wrap it in appropriate synchronization primitives (e.g., `Mutex`, `RwLock`).
54
55mod bounded;
56mod config;
57mod policy;
58
59pub use bounded::{BoundedQueue, QueueStats};
60pub use config::QueueConfig;
61pub use policy::QueueOverflowPolicy;