Skip to main content

InflectableEntry

Trait InflectableEntry 

Source
pub trait InflectableEntry<NS: NameStyle = Identity> {
    // Required method
    fn write<'a>(&'a self, w: &mut impl EntryWriter<'a>);

    // Provided method
    fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement> { ... }
}
Expand description

A trait for metric entries where the names of the fields can be “inflected” using a NameStyle. This defines the interface for metric sources that want to be able to generate metric structs that can be renamed without having any string operations happen at runtime.

Both InflectableEntry and Entry are intended to be “pure” structs - all references to channels, counters and the like are expected to be resolved when creating the InflectableEntry.

An InflectableEntry with any specific set of type parameters is equivalent to an Entry. It should be wrapped by a wrapper that implements Entry and delegates to it with a particular set of type parameters, for example RootEntry, and then emitting that to an EntrySink.

The normal way of generating a metric entry is by starting with a struct that implements CloseEntry (that is generally generated using the #[metrics] macro), wrapping it in a RootEntry to generate an Entry, and then emitting that to an entry sink.

Design note: in theory you could have a world where InflectableEntry and Entry are the same trait (where the sinks use the default type parameters). In practice, it is desired that the trait Entry will have very few breaking changes since it needs to be identical throughout a program that wants to emit metrics to a single destination, and therefore InflectableEntry is kept separate.

§Manual Implementations

Currently, there is no (stable) non-macro way of generating an InflectableEntry that actually inflects names. If you want to make a manual entry, it is recommended to implement the Entry trait, then use a field with #[metrics(flatten_entry)] as follows - though note that this will ignore inflections:

use metrique::unit_of_work::metrics;
use metrique::writer::{Entry, EntryWriter};

struct MyCustomEntry;

impl Entry for MyCustomEntry {
    fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
        writer.value("custom", "custom");
    }
}

#[metrics]
struct MyMetric {
    #[metrics(flatten_entry, no_close)]
    field: MyCustomEntry,
}

Required Methods§

Source

fn write<'a>(&'a self, w: &mut impl EntryWriter<'a>)

Write this metric entry to an EntryWriter

Provided Methods§

Source

fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement>

Sample group

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<NS: NameStyle, T: InflectableEntry<NS> + ?Sized> InflectableEntry<NS> for Arc<T>

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement>

Source§

impl<NS: NameStyle, T: InflectableEntry<NS> + ?Sized> InflectableEntry<NS> for Box<T>

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement>

Source§

impl<NS: NameStyle, T: InflectableEntry<NS> + ToOwned + ?Sized> InflectableEntry<NS> for Cow<'_, T>

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement>

Source§

impl<NS: NameStyle, T: InflectableEntry<NS>, F: FlagConstructor> InflectableEntry<NS> for ForceFlag<T, F>

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

impl<NS: NameStyle, T: InflectableEntry<NS>, const N: usize> InflectableEntry<NS> for WithDimensions<T, N>

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

impl<NS: NameStyle, T: InflectableEntry<NS>> InflectableEntry<NS> for &T

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement>

Source§

impl<NS: NameStyle, T: InflectableEntry<NS>> InflectableEntry<NS> for Option<T>

Source§

fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>)

Source§

fn sample_group(&self) -> impl Iterator<Item = SampleGroupElement>

Implementors§