pub struct AnomalyMonitor<K> { /* private fields */ }Expand description
Composes one or more AnomalyRules into a single observer
over a ProtocolEvent stream.
Owns a reusable scratch Vec<Anomaly<K>> so each call to
observe / on_tick doesn’t
re-allocate when rules emit nothing — the typical case.
Implementations§
Source§impl<K> AnomalyMonitor<K>
impl<K> AnomalyMonitor<K>
Sourcepub fn with_rule<R: AnomalyRule<K> + 'static>(self, rule: R) -> Self
pub fn with_rule<R: AnomalyRule<K> + 'static>(self, rule: R) -> Self
Builder-style add — consumes and returns self.
Sourcepub fn add_rule<R: AnomalyRule<K> + 'static>(&mut self, rule: R)
pub fn add_rule<R: AnomalyRule<K> + 'static>(&mut self, rule: R)
In-place add — for cases where the rule set is computed
dynamically. The Box<dyn ..> allocation matches the static
with_rule form.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Number of rules registered.
Sourcepub fn rule_names(&self) -> impl Iterator<Item = &'static str> + '_
pub fn rule_names(&self) -> impl Iterator<Item = &'static str> + '_
Rule names in insertion order — useful for logging / metrics setup.
Sourcepub fn observe(&mut self, evt: &ProtocolEvent<K>) -> Vec<Anomaly<K>>
pub fn observe(&mut self, evt: &ProtocolEvent<K>) -> Vec<Anomaly<K>>
Push evt through every registered rule and return any
resulting anomalies. The returned Vec is freshly
allocated each call so the caller can keep it without
fighting the borrow checker; the internal scratch buffer
is left empty for the next call.
Trait Implementations§
Source§impl<K> Debug for AnomalyMonitor<K>
impl<K> Debug for AnomalyMonitor<K>
Auto Trait Implementations§
impl<K> !RefUnwindSafe for AnomalyMonitor<K>
impl<K> !Sync for AnomalyMonitor<K>
impl<K> !UnwindSafe for AnomalyMonitor<K>
impl<K> Freeze for AnomalyMonitor<K>
impl<K> Send for AnomalyMonitor<K>where
K: Send,
impl<K> Unpin for AnomalyMonitor<K>where
K: Unpin,
impl<K> UnsafeUnpin for AnomalyMonitor<K>
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