tower_load

Trait Instrument

Source
pub trait Instrument<H, V>: Clone {
    type Output;

    // Required method
    fn instrument(&self, handle: H, value: V) -> Self::Output;
}
Expand description

Attaches I-typed instruments to V typed values.

This utility allows load metrics to have a protocol-agnostic means to track streams past their initial response future. For example, if V represents an HTTP response type, an implementation could add H-typed handles to each response’s extensions to detect when the response is dropped.

Handles are intended to be RAII guards that primarily implement Drop and update load metric state as they are dropped.

A base impl<H, V> Instrument<H, V> for NoInstrument is provided to drop the handle immediately. This is appropriate when a response is discrete and cannot comprise multiple messages.

In many cases, the Output type is simply V. However, Instrument may alter the type in order to instrument it appropriately. For example, an HTTP Instrument may modify the body type: so an Instrument that takes values of type http::Response<A> may output values of type http::Response<B>.

Required Associated Types§

Source

type Output

The instrumented value type.

Required Methods§

Source

fn instrument(&self, handle: H, value: V) -> Self::Output

Attaches an H-typed handle to a V-typed value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<H, V> Instrument<H, V> for NoInstrument