From ff4795e74fbe97eb51bf2061961ea2f430222431 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Sat, 17 Oct 2020 17:38:13 +0300 Subject: [PATCH] Add a const constructor for KeyData (#106) --- metrics/src/key.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/metrics/src/key.rs b/metrics/src/key.rs index 4609bb9..4e3c213 100644 --- a/metrics/src/key.rs +++ b/metrics/src/key.rs @@ -36,6 +36,16 @@ impl KeyData { } } + /// Creates a `KeyData` from a static name. + /// + /// This function is const, so it can be used in a static context. + pub const fn from_static_name(name: &'static str) -> Self { + Self { + name: ScopedString::Borrowed(name), + labels: Vec::new(), + } + } + /// Name of this key. pub fn name(&self) -> &ScopedString { &self.name