pub struct MessageRateMonitor { /* private fields */ }Expand description
Message rate monitor for detecting high-frequency message scenarios.
This utility helps backends detect when message rates exceed a threshold and log warnings as specified in FR-016. It does not perform any automatic throttling or backpressure - it only logs warnings for user awareness.
§Usage
Backends can use this to monitor receive rates:
ⓘ
use canlink_hal::backend::MessageRateMonitor;
let mut monitor = MessageRateMonitor::new(1000); // Warn above 1000 msg/s
// In receive loop:
if let Some(msg) = backend.receive_message()? {
monitor.record_message();
process(msg);
}§Thread Safety
This struct is not thread-safe. Each thread should have its own monitor or use external synchronization.
Implementations§
Source§impl MessageRateMonitor
impl MessageRateMonitor
Sourcepub fn record_message(&mut self) -> bool
pub fn record_message(&mut self) -> bool
Record a message and check if rate exceeds threshold.
Returns true if the rate exceeds the threshold (warning should be logged).
Only returns true once per measurement window to avoid log spam.
§Examples
use canlink_hal::backend::MessageRateMonitor;
let mut monitor = MessageRateMonitor::new(1000);
// Record messages
if monitor.record_message() {
// Rate exceeded threshold - handle warning
eprintln!("Warning: High message rate detected");
}Sourcepub fn current_count(&self) -> u32
pub fn current_count(&self) -> u32
Get the current message count in this window.
Trait Implementations§
Source§impl Debug for MessageRateMonitor
impl Debug for MessageRateMonitor
Auto Trait Implementations§
impl Freeze for MessageRateMonitor
impl RefUnwindSafe for MessageRateMonitor
impl Send for MessageRateMonitor
impl Sync for MessageRateMonitor
impl Unpin for MessageRateMonitor
impl UnsafeUnpin for MessageRateMonitor
impl UnwindSafe for MessageRateMonitor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more