metricrs/
derive.rs

1pub use metricrs_derive::*;
2
3use crate::Token;
4
5/// Kind of the `#[metricrs::instrument]` driving.
6pub enum DeriveKind {
7    /// A `counter` measuring instrument.
8    Counter,
9    /// A `timer` measuring instrument.
10    Timer,
11    /// A `gauge` measuring instrument.
12    Gauge,
13}
14
15/// Instrument options set directly by the user in `#[metricrs::instrument]`.
16#[derive(Default)]
17pub struct DeriveOption<'a> {
18    /// Driving instrument `type`.
19    pub kind: Option<DeriveKind>,
20    /// Set the `name` of generating instrument .
21    pub name: Option<&'a str>,
22    /// Attach labels to this instrument.
23    pub labels: Option<&'a [(&'a str, &'a str)]>,
24}
25
26impl<'a> From<DeriveOption<'a>> for Token<'a> {
27    fn from(value: DeriveOption<'a>) -> Self {
28        Self::new(
29            value.name.unwrap_or(concat!(module_path!(), column!())),
30            value.labels.unwrap_or_default(),
31        )
32    }
33}