Skip to content

Commit c664a01

Browse files
Javyretobz
andauthored
add KeyName -> std::Cow paths (#640)
Co-authored-by: Toby Lawrence <tobz@users.noreply.github.com>
1 parent 4c0a319 commit c664a01

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

metrics/src/key.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ impl KeyName {
2323
pub fn as_str(&self) -> &str {
2424
&self.0
2525
}
26+
27+
/// Consumes this [`KeyName`], returning the inner [`SharedString`].
28+
pub fn into_inner(self) -> SharedString {
29+
self.0
30+
}
2631
}
2732

2833
impl<T> From<T> for KeyName
@@ -40,6 +45,12 @@ impl Borrow<str> for KeyName {
4045
}
4146
}
4247

48+
impl From<KeyName> for std::borrow::Cow<'static, str> {
49+
fn from(name: KeyName) -> Self {
50+
name.0.into()
51+
}
52+
}
53+
4354
/// A metric identifier.
4455
///
4556
/// A key represents both the name and labels of a metric.
@@ -131,6 +142,11 @@ impl Key {
131142
self.name.0.as_ref()
132143
}
133144

145+
/// Name of this key as a [`KeyName`]
146+
pub fn name_shared(&self) -> KeyName {
147+
self.name.clone()
148+
}
149+
134150
/// Labels of this key, if they exist.
135151
pub fn labels(&self) -> Iter<'_, Label> {
136152
self.labels.iter()

0 commit comments

Comments
 (0)