Skip to content

How to pass labels as a function argument? #349

Answered by tobz
jaskij asked this question in Q&A
Discussion options

You must be logged in to vote

That's certainly one way to do it, yeah.

In this case, based on the given construction, both the metric name and labels are considered "non static", so it will end up calling metrics::Key::from_parts(metric_name, labels) to construct the key. That method depends on IntoLabels, which you could also use here to generalize your function, if you wanted to do so:

pub(crate) fn new_with_metric_name<L>(
    db: Database,
    engine: EngineId,
    metric_name: &'static str,
    labels: Option<L>,
) -> Self
where
  L: metrics::IntoLabels,
{
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jaskij
Comment options

Answer selected by jaskij
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants