pub trait WatermarkHandler: Send + Sync {
// Required methods
fn on_warn(&self, event: WatermarkEvent);
fn on_critical(&self, event: WatermarkEvent);
fn on_oom(&self, event: WatermarkEvent);
}Expand description
Callback handler invoked on threshold crossings and on OOM.
Implementations must be cheap — they run on the allocation hot path. Set a flag, write to a non-blocking channel, or increment a metric; avoid blocking I/O.
§Panic safety
Handler methods MUST NOT panic. If on_warn / on_critical panics
after the inner allocator has already issued a block, Watermark
unwinds out of allocate without returning the block to the
caller — the slot is carved on the inner allocator and the
allocated counter has been incremented, but the caller never
receives the pointer and so can never free it. The block is leaked
for the lifetime of the inner allocator. If on_oom panics, the
caller’s AllocError is replaced by the panic; no block was issued
and the counters are unchanged, so this case is consistent but
noisier.
If your handler can fail (e.g. it writes to a possibly-full channel), absorb the failure inside the handler — set a flag, log, silently drop the event — rather than letting it escape. Treat handler-level panics as a fatal bug in your monitoring code.
Required Methods§
Sourcefn on_warn(&self, event: WatermarkEvent)
fn on_warn(&self, event: WatermarkEvent)
Called once per crossing of the warn_pct threshold (rising edge).
Sourcefn on_critical(&self, event: WatermarkEvent)
fn on_critical(&self, event: WatermarkEvent)
Called once per crossing of the critical_pct threshold (rising edge).
Sourcefn on_oom(&self, event: WatermarkEvent)
fn on_oom(&self, event: WatermarkEvent)
Called when an allocation returns AllocError.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl WatermarkHandler for LogHandler
std only.