pub trait ContextWatcher: Send + Sync {
// Provided methods
fn on_inject(&self, msg: &dyn Debug, pos: Position) -> WatcherVerdict { ... }
fn on_remove(&self, count: usize) -> WatcherVerdict { ... }
fn on_pre_compact(&self, message_count: usize) -> WatcherVerdict { ... }
fn on_post_compact(&self, removed: usize, remaining: usize) { ... }
}Expand description
Observer and gatekeeper for mutations to an OperatorContext.
All methods have default implementations that approve the operation (Allow or no-op). Implementors override only the methods they care about.
Watchers are stored as Arc<dyn ContextWatcher> and must be Send + Sync.
Long-running or I/O-heavy watcher logic will add latency to every mutation; keep
implementations fast.
§Object safety
The trait is object-safe. on_inject receives the message as a type-erased
fmt::Debug reference (the concrete ContextMessage<M>) so implementations
can inspect its debug representation without requiring a generic method.
Provided Methods§
Sourcefn on_inject(&self, msg: &dyn Debug, pos: Position) -> WatcherVerdict
fn on_inject(&self, msg: &dyn Debug, pos: Position) -> WatcherVerdict
Called before a message is injected.
msg is the full ContextMessage<M> coerced to &dyn fmt::Debug.
pos is the requested injection position.
Return WatcherVerdict::Reject to abort the inject.
Sourcefn on_remove(&self, count: usize) -> WatcherVerdict
fn on_remove(&self, count: usize) -> WatcherVerdict
Called before messages are removed (truncate or filter operations).
count is the number of messages about to be removed.
Return WatcherVerdict::Reject to abort the removal.
Sourcefn on_pre_compact(&self, message_count: usize) -> WatcherVerdict
fn on_pre_compact(&self, message_count: usize) -> WatcherVerdict
Called before a OperatorContext::replace_messages compaction runs.
message_count is the number of messages currently in the context.
Return WatcherVerdict::Reject to abort the compaction.
Sourcefn on_post_compact(&self, removed: usize, remaining: usize)
fn on_post_compact(&self, removed: usize, remaining: usize)
Called after a OperatorContext::replace_messages compaction completes.
removed is the number of messages dropped (old_count - new_count, clamped to 0).
remaining is the count of messages now in the context.