tracing_subscriber::field

Trait RecordFields

Source
pub trait RecordFields: Sealed<RecordFieldsMarker> {
    // Required method
    fn record(&self, visitor: &mut dyn Visit);
}
Expand description

Extension trait implemented by types which can be recorded by a visitor.

This allows writing code that is generic over tracing_core’s span::Attributes, span::Record, and Event types. These types all provide inherent record methods that allow a visitor to record their fields, but there is no common trait representing this.

With RecordFields, we can write code like this:

use tracing_core::field::Visit;
use tracing_subscriber::field::RecordFields;

struct MyVisitor {
    // ...
}
impl Visit for MyVisitor {
    // ...
}

fn record_with_my_visitor<R>(r: R)
where
    R: RecordFields,
{
    let mut visitor = MyVisitor::new();
    r.record(&mut visitor);
}

Required Methods§

Source

fn record(&self, visitor: &mut dyn Visit)

Record all the fields in self with the provided visitor.

Implementations on Foreign Types§

Source§

impl RecordFields for Event<'_>

Source§

fn record(&self, visitor: &mut dyn Visit)

Source§

impl RecordFields for Attributes<'_>

Source§

fn record(&self, visitor: &mut dyn Visit)

Source§

impl RecordFields for Record<'_>

Source§

fn record(&self, visitor: &mut dyn Visit)

Source§

impl<F> RecordFields for &F
where F: RecordFields,

Source§

fn record(&self, visitor: &mut dyn Visit)

Implementors§