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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use std::ops::{Add, AddAssign};
pub trait Span: core::fmt::Debug + Clone + core::ops::AddAssign {}
impl<T: core::fmt::Debug + Clone + core::ops::AddAssign> Span for T {}
pub trait Spanned {
type Span: Span;
fn span(&self) -> Option<Self::Span>;
}
#[cfg(feature = "smallvec")]
type KeysSmallVecArray = [String; 10];
#[cfg(feature = "smallvec")]
type KeysInner = smallvec_crate::SmallVec<KeysSmallVecArray>;
#[cfg(not(feature = "smallvec"))]
type KeysInner = Vec<String>;
#[derive(Debug, Default, Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct Keys(KeysInner);
impl Keys {
pub fn new() -> Self {
Keys(KeysInner::new())
}
pub fn with_capacity(cap: usize) -> Self {
Keys(KeysInner::with_capacity(cap))
}
pub fn iter(&self) -> impl Iterator<Item = &String> {
self.0.iter()
}
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.0.iter_mut()
}
pub fn dotted(&self) -> String {
self.0.join(".")
}
pub fn push(&mut self, value: String) {
self.0.push(value)
}
pub fn into_inner(self) -> KeysInner {
self.0
}
}
impl AddAssign for Keys {
fn add_assign(&mut self, rhs: Self) {
self.0.extend(rhs.0.into_iter())
}
}
impl<S: ToString> Add<S> for Keys {
type Output = Self;
fn add(mut self, rhs: S) -> Self::Output {
self.push(rhs.to_string());
self
}
}
impl From<String> for Keys {
fn from(s: String) -> Self {
let mut v = Self::new();
v.push(s);
v
}
}
impl IntoIterator for Keys {
type Item = <KeysInner as IntoIterator>::Item;
#[cfg(feature = "smallvec")]
type IntoIter = smallvec_crate::IntoIter<KeysSmallVecArray>;
#[cfg(not(feature = "smallvec"))]
type IntoIter = std::vec::IntoIter<String>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}