Skip to main content

LabelValue

Trait LabelValue 

Source
pub trait LabelValue {
    // Required method
    fn label_value(&self) -> Value;
}
Expand description

Value types that can be used as metric labels.

Implemented out of the box for strings, integers, bool, and char. Implement this trait for custom enums to use them as labels:

ⓘ
enum Plan { Free, Paid }

impl LabelValue for Plan {
    fn label_value(&self) -> Value {
        match self {
            Plan::Free => "free",
            Plan::Paid => "paid",
        }
        .into()
    }
}

Required Methods§

Source

fn label_value(&self) -> Value

Converts this value into an OpenTelemetry attribute Value (string, integer, or bool).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl LabelValue for Cow<'_, str>

Source§

impl LabelValue for String

Source§

impl LabelValue for bool

Source§

impl LabelValue for char

Source§

impl LabelValue for i8

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for i16

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for i32

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for i64

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for isize

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for str

Source§

impl LabelValue for u8

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for u16

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for u32

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for u64

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl LabelValue for usize

Source§

fn label_value(&self) -> Value

Converts to an i64 attribute value, clamping values above i64::MAX.

Source§

impl<T: LabelValue + ?Sized> LabelValue for &T

Implementors§