1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::SharedString;
use alloc::vec::Vec;
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub struct Label(pub(crate) SharedString, pub(crate) SharedString);
impl Label {
pub fn new<K, V>(key: K, value: V) -> Self
where
K: Into<SharedString>,
V: Into<SharedString>,
{
Label(key.into(), value.into())
}
pub const fn from_static_parts(key: &'static str, value: &'static str) -> Self {
Label(SharedString::const_str(key), SharedString::const_str(value))
}
pub fn key(&self) -> &str {
self.0.as_ref()
}
pub fn value(&self) -> &str {
self.1.as_ref()
}
pub fn into_parts(self) -> (SharedString, SharedString) {
(self.0, self.1)
}
}
impl<K, V> From<&(K, V)> for Label
where
K: Into<SharedString> + Clone,
V: Into<SharedString> + Clone,
{
fn from(pair: &(K, V)) -> Label {
Label::new(pair.0.clone(), pair.1.clone())
}
}
pub trait IntoLabels {
fn into_labels(self) -> Vec<Label>;
}
impl IntoLabels for Vec<Label> {
fn into_labels(self) -> Vec<Label> {
self
}
}
impl<T, L> IntoLabels for &T
where
Self: IntoIterator<Item = L>,
L: Into<Label>,
{
fn into_labels(self) -> Vec<Label> {
self.into_iter().map(|l| l.into()).collect()
}
}