linkml 1.9.4rc2__py3-none-any.whl → 1.9.5rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- linkml/cli/main.py +4 -0
- linkml/generators/__init__.py +2 -0
- linkml/generators/common/build.py +5 -20
- linkml/generators/common/template.py +289 -3
- linkml/generators/docgen.py +55 -10
- linkml/generators/erdiagramgen.py +9 -5
- linkml/generators/graphqlgen.py +32 -6
- linkml/generators/jsonldcontextgen.py +78 -12
- linkml/generators/jsonschemagen.py +29 -12
- linkml/generators/mermaidclassdiagramgen.py +21 -3
- linkml/generators/owlgen.py +4 -1
- linkml/generators/panderagen/dataframe_class.py +13 -0
- linkml/generators/panderagen/dataframe_field.py +50 -0
- linkml/generators/panderagen/linkml_pandera_validator.py +186 -0
- linkml/generators/panderagen/panderagen.py +22 -5
- linkml/generators/panderagen/panderagen_class_based/class.jinja2 +70 -13
- linkml/generators/panderagen/panderagen_class_based/custom_checks.jinja2 +27 -0
- linkml/generators/panderagen/panderagen_class_based/enums.jinja2 +3 -3
- linkml/generators/panderagen/panderagen_class_based/pandera.jinja2 +12 -2
- linkml/generators/panderagen/panderagen_class_based/slots.jinja2 +19 -17
- linkml/generators/panderagen/slot_generator_mixin.py +143 -16
- linkml/generators/panderagen/transforms/__init__.py +19 -0
- linkml/generators/panderagen/transforms/collection_dict_model_transform.py +62 -0
- linkml/generators/panderagen/transforms/list_dict_model_transform.py +66 -0
- linkml/generators/panderagen/transforms/model_transform.py +8 -0
- linkml/generators/panderagen/transforms/nested_struct_model_transform.py +27 -0
- linkml/generators/panderagen/transforms/simple_dict_model_transform.py +86 -0
- linkml/generators/plantumlgen.py +17 -11
- linkml/generators/pydanticgen/pydanticgen.py +53 -2
- linkml/generators/pydanticgen/template.py +45 -233
- linkml/generators/pydanticgen/templates/attribute.py.jinja +1 -0
- linkml/generators/pydanticgen/templates/base_model.py.jinja +16 -2
- linkml/generators/pydanticgen/templates/imports.py.jinja +1 -1
- linkml/generators/rdfgen.py +11 -2
- linkml/generators/rustgen/__init__.py +3 -0
- linkml/generators/rustgen/build.py +94 -0
- linkml/generators/rustgen/cli.py +65 -0
- linkml/generators/rustgen/rustgen.py +1038 -0
- linkml/generators/rustgen/template.py +865 -0
- linkml/generators/rustgen/templates/Cargo.toml.jinja +42 -0
- linkml/generators/rustgen/templates/anything.rs.jinja +142 -0
- linkml/generators/rustgen/templates/as_key_value.rs.jinja +56 -0
- linkml/generators/rustgen/templates/class_module.rs.jinja +8 -0
- linkml/generators/rustgen/templates/enum.rs.jinja +54 -0
- linkml/generators/rustgen/templates/file.rs.jinja +62 -0
- linkml/generators/rustgen/templates/import.rs.jinja +4 -0
- linkml/generators/rustgen/templates/imports.rs.jinja +8 -0
- linkml/generators/rustgen/templates/poly.rs.jinja +9 -0
- linkml/generators/rustgen/templates/poly_containers.rs.jinja +439 -0
- linkml/generators/rustgen/templates/poly_trait.rs.jinja +15 -0
- linkml/generators/rustgen/templates/poly_trait_impl.rs.jinja +5 -0
- linkml/generators/rustgen/templates/poly_trait_impl_orsubtype.rs.jinja +5 -0
- linkml/generators/rustgen/templates/poly_trait_property.rs.jinja +8 -0
- linkml/generators/rustgen/templates/poly_trait_property_impl.rs.jinja +132 -0
- linkml/generators/rustgen/templates/poly_trait_property_match.rs.jinja +10 -0
- linkml/generators/rustgen/templates/property.rs.jinja +19 -0
- linkml/generators/rustgen/templates/pyproject.toml.jinja +10 -0
- linkml/generators/rustgen/templates/serde_utils.rs.jinja +310 -0
- linkml/generators/rustgen/templates/slot_range_as_union.rs.jinja +61 -0
- linkml/generators/rustgen/templates/struct.rs.jinja +75 -0
- linkml/generators/rustgen/templates/struct_or_subtype_enum.rs.jinja +108 -0
- linkml/generators/rustgen/templates/typealias.rs.jinja +13 -0
- linkml/generators/sqltablegen.py +18 -16
- linkml/generators/yarrrmlgen.py +157 -0
- linkml/linter/config/datamodel/config.py +160 -293
- linkml/linter/config/datamodel/config.yaml +34 -26
- linkml/linter/config/default.yaml +4 -0
- linkml/linter/config/recommended.yaml +4 -0
- linkml/linter/linter.py +1 -2
- linkml/linter/rules.py +37 -0
- linkml/utils/schemaloader.py +55 -3
- {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/METADATA +1 -1
- {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/RECORD +76 -38
- {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/entry_points.txt +1 -0
- linkml/generators/panderagen/panderagen_class_based/mixins.jinja2 +0 -26
- {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/WHEEL +0 -0
- {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
hash::Hash,
|
|
3
|
+
collections::HashMap,
|
|
4
|
+
iter::{Map, IntoIterator},
|
|
5
|
+
ops::{Index, IndexMut},
|
|
6
|
+
slice,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/* ------------------------------------------------------------------- *
|
|
10
|
+
* Immutable view
|
|
11
|
+
* ------------------------------------------------------------------- */
|
|
12
|
+
|
|
13
|
+
pub struct ListView<'a, T> {
|
|
14
|
+
inner: &'a [Box<T>],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ViewIter<'a, T> =
|
|
18
|
+
std::iter::Map<
|
|
19
|
+
std::slice::Iter<'a, Box<T>>,
|
|
20
|
+
fn(&'a Box<T>) -> &'a T,
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
impl<'a, T> ListView<'a, T> {
|
|
25
|
+
|
|
26
|
+
pub fn len(&self) -> usize { self.inner.len() }
|
|
27
|
+
pub fn is_empty(&self) -> bool { self.inner.is_empty() }
|
|
28
|
+
|
|
29
|
+
pub fn get(&self, i: usize) -> Option<&T> {
|
|
30
|
+
self.inner.get(i).map(|b| &**b)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pub fn new(inner: &'a [Box<T>]) -> ListView<'a, T> {
|
|
34
|
+
Self { inner : inner }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
pub fn iter(&self) -> ViewIter<'a, T> {
|
|
39
|
+
self.inner.iter().map(debox)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Index (`view[i]`) */
|
|
44
|
+
impl<'a, T> Index<usize> for ListView<'a, T> {
|
|
45
|
+
type Output = T;
|
|
46
|
+
fn index(&self, i: usize) -> &Self::Output { &*self.inner[i] }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* &ListView iteration (`for x in &view`) */
|
|
50
|
+
type Iter<'a, T> = Map<slice::Iter<'a, Box<T>>, fn(&'a Box<T>) -> &'a T>;
|
|
51
|
+
fn debox<'a, T>(b: &'a Box<T>) -> &'a T { &**b }
|
|
52
|
+
|
|
53
|
+
impl<'a, T> IntoIterator for &'a ListView<'a, T> {
|
|
54
|
+
type Item = &'a T;
|
|
55
|
+
type IntoIter = Iter<'a, T>;
|
|
56
|
+
fn into_iter(self) -> Self::IntoIter { self.inner.iter().map(debox) }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* ------------------------------------------------------------------- *
|
|
60
|
+
* Mutable view
|
|
61
|
+
* ------------------------------------------------------------------- */
|
|
62
|
+
|
|
63
|
+
pub struct ListViewMut<'a, T> {
|
|
64
|
+
inner: &'a mut Vec<Box<T>>,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
impl<'a, T> ListViewMut<'a, T> {
|
|
68
|
+
pub fn len(&self) -> usize { self.inner.len() }
|
|
69
|
+
pub fn is_empty(&self) -> bool { self.inner.is_empty() }
|
|
70
|
+
|
|
71
|
+
pub fn new(inner: &'a mut Vec<Box<T>>) -> ListViewMut<'a, T> {
|
|
72
|
+
Self { inner : inner }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
pub fn get(&self, i: usize) -> Option<&T> {
|
|
76
|
+
self.inner.get(i).map(|b| &**b)
|
|
77
|
+
}
|
|
78
|
+
pub fn get_mut(&mut self, i: usize) -> Option<&mut T> {
|
|
79
|
+
self.inner.get_mut(i).map(|b| &mut **b)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
pub fn push(&mut self, v: T) {
|
|
83
|
+
self.inner.push(Box::new(v));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pub fn iter(&self) -> Iter<'_, T> {
|
|
87
|
+
self.inner.iter().map(debox)
|
|
88
|
+
}
|
|
89
|
+
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
|
|
90
|
+
self.inner.iter_mut().map(debox_mut)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Index / IndexMut */
|
|
95
|
+
impl<'a, T> Index<usize> for ListViewMut<'a, T> {
|
|
96
|
+
type Output = T;
|
|
97
|
+
fn index(&self, i: usize) -> &Self::Output { &*self.inner[i] }
|
|
98
|
+
}
|
|
99
|
+
impl<'a, T> IndexMut<usize> for ListViewMut<'a, T> {
|
|
100
|
+
fn index_mut(&mut self, i: usize) -> &mut Self::Output { &mut *self.inner[i] }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* &mut ListViewMut iteration (`for x in &mut view`) */
|
|
104
|
+
fn debox_mut<'a, T>(b: &'a mut Box<T>) -> &'a mut T { &mut **b }
|
|
105
|
+
type IterMut<'a, T> = Map<slice::IterMut<'a, Box<T>>, fn(&'a mut Box<T>) -> &'a mut T>;
|
|
106
|
+
|
|
107
|
+
impl<'a, T> IntoIterator for &'a ListViewMut<'a, T> {
|
|
108
|
+
type Item = &'a T;
|
|
109
|
+
type IntoIter = Iter<'a, T>;
|
|
110
|
+
fn into_iter(self) -> Self::IntoIter { self.inner.iter().map(debox) }
|
|
111
|
+
}
|
|
112
|
+
impl<'a, T> IntoIterator for &'a mut ListViewMut<'a, T> {
|
|
113
|
+
type Item = &'a mut T;
|
|
114
|
+
type IntoIter = IterMut<'a, T>;
|
|
115
|
+
fn into_iter(self) -> Self::IntoIter { self.inner.iter_mut().map(debox_mut) }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
pub struct MapView<'a, K, V> {
|
|
120
|
+
inner: &'a HashMap<K, Box<V>>,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
impl<'a, K: Eq + Hash, V> MapView<'a, K, V> {
|
|
124
|
+
/* basic info */
|
|
125
|
+
pub fn len(&self) -> usize { self.inner.len() }
|
|
126
|
+
pub fn is_empty(&self) -> bool { self.inner.is_empty() }
|
|
127
|
+
|
|
128
|
+
/* look-ups */
|
|
129
|
+
pub fn get(&self, k: &K) -> Option<&V> {
|
|
130
|
+
self.inner.get(k).map(debox)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pub fn new(inner: &'a HashMap<K, Box<V>>) -> Self {
|
|
134
|
+
Self { inner : inner }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)> + '_ {
|
|
138
|
+
self.inner.iter().map(as_pair)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* &MapView iteration */
|
|
144
|
+
type MapIter<'a, K, V> =
|
|
145
|
+
Map<std::collections::hash_map::Iter<'a, K, Box<V>>, fn((&'a K,&'a Box<V>)) -> (&'a K,&'a V)>;
|
|
146
|
+
|
|
147
|
+
fn as_pair<'a, K, V>((k, v): (&'a K, &'a Box<V>)) -> (&'a K, &'a V) { (k, &**v) }
|
|
148
|
+
|
|
149
|
+
impl<'a, K: Eq + Hash, V> IntoIterator for &'a MapView<'a, K, V> {
|
|
150
|
+
type Item = (&'a K, &'a V);
|
|
151
|
+
type IntoIter = MapIter<'a, K, V>;
|
|
152
|
+
fn into_iter(self) -> Self::IntoIter { self.inner.iter().map(as_pair) }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* ------------------------------- mutable view ---------------------- */
|
|
156
|
+
pub struct MapViewMut<'a, K, V> {
|
|
157
|
+
inner: &'a mut HashMap<K, Box<V>>,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
impl<'a, K: Eq + Hash, V> MapViewMut<'a, K, V> {
|
|
161
|
+
/* same basic info */
|
|
162
|
+
pub fn len(&self) -> usize { self.inner.len() }
|
|
163
|
+
pub fn is_empty(&self) -> bool { self.inner.is_empty() }
|
|
164
|
+
|
|
165
|
+
/* look-ups */
|
|
166
|
+
pub fn get(&self, k: &K) -> Option<&V> { self.inner.get(k).map(debox) }
|
|
167
|
+
pub fn get_mut(&mut self, k: &K) -> Option<&mut V> { self.inner.get_mut(k).map(debox_mut) }
|
|
168
|
+
|
|
169
|
+
/* insertion / removal */
|
|
170
|
+
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
|
|
171
|
+
self.inner.insert(k, Box::new(v)).map(|old| *old)
|
|
172
|
+
}
|
|
173
|
+
pub fn remove(&mut self, k: &K) -> Option<V> {
|
|
174
|
+
self.inner.remove(k).map(|b| *b)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* iterators */
|
|
178
|
+
pub fn iter<'b>(&'b self) -> MapIter<'b, K, V> {
|
|
179
|
+
self.inner.iter().map(as_pair)
|
|
180
|
+
}
|
|
181
|
+
pub fn iter_mut<'b>(&'b mut self) -> MapIterMut<'b, K, V> {
|
|
182
|
+
self.inner.iter_mut().map(as_pair_mut)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* &mut MapViewMut iteration */
|
|
187
|
+
type MapIterMut<'a, K, V> =
|
|
188
|
+
Map<std::collections::hash_map::IterMut<'a, K, Box<V>>,
|
|
189
|
+
fn((&'a K,&'a mut Box<V>)) -> (&'a K,&'a mut V)>;
|
|
190
|
+
|
|
191
|
+
fn as_pair_mut<'a, K, V>((k, v): (&'a K, &'a mut Box<V>)) -> (&'a K, &'a mut V) { (k, &mut **v) }
|
|
192
|
+
|
|
193
|
+
impl<'a, K: Eq + Hash, V> IntoIterator for &'a mut MapViewMut<'a, K, V> {
|
|
194
|
+
type Item = (&'a K, &'a mut V);
|
|
195
|
+
type IntoIter = MapIterMut<'a, K, V>;
|
|
196
|
+
fn into_iter(self) -> Self::IntoIter { self.inner.iter_mut().map(as_pair_mut) }
|
|
197
|
+
}
|
|
198
|
+
/* also allow &MapViewMut to iterate immutably */
|
|
199
|
+
impl<'a, K: Eq + Hash, V> IntoIterator for &'a MapViewMut<'a, K, V> {
|
|
200
|
+
type Item = (&'a K, &'a V);
|
|
201
|
+
type IntoIter = MapIter<'a, K, V>;
|
|
202
|
+
fn into_iter(self) -> Self::IntoIter { self.inner.iter().map(as_pair) }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
pub trait MapRef<'l, K, V> {
|
|
207
|
+
fn get(&self, k: &K) -> Option<&V>;
|
|
208
|
+
fn len(&self) -> usize;
|
|
209
|
+
fn is_empty(&self) -> bool { self.len() == 0 }
|
|
210
|
+
|
|
211
|
+
type Iter<'a>: Iterator<Item = (&'a K, &'a V)>
|
|
212
|
+
where
|
|
213
|
+
Self: 'a,
|
|
214
|
+
K: 'a,
|
|
215
|
+
V: 'a;
|
|
216
|
+
|
|
217
|
+
fn iter(&self) -> Self::Iter<'_>;
|
|
218
|
+
|
|
219
|
+
fn to_any(self) -> MapAny<'l, K, V>
|
|
220
|
+
where
|
|
221
|
+
Self: Sized; // keeps it object-safe enough for static dispatch
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
/* NEW — borrowed map */
|
|
226
|
+
impl<'a, K: Eq + Hash, V> MapRef<'a, K, V> for &'a HashMap<K, V> {
|
|
227
|
+
fn get(&self, k: &K) -> Option<&V> { (*self).get(k) }
|
|
228
|
+
fn len(&self) -> usize { (*self).len() }
|
|
229
|
+
|
|
230
|
+
type Iter<'b> = std::collections::hash_map::Iter<'b, K, V>
|
|
231
|
+
where
|
|
232
|
+
Self: 'b,
|
|
233
|
+
K: 'b,
|
|
234
|
+
V: 'b;
|
|
235
|
+
|
|
236
|
+
fn iter(&self) -> Self::Iter<'a> {
|
|
237
|
+
(*self).iter()
|
|
238
|
+
}
|
|
239
|
+
fn to_any(self) -> MapAny<'a, K, V>
|
|
240
|
+
where
|
|
241
|
+
Self: Sized
|
|
242
|
+
{
|
|
243
|
+
MapAny::Hash(self)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* ---- impl for your borrowing MapView ---------------------------- */
|
|
248
|
+
impl<'a, K: std::hash::Hash + Eq, V> MapRef<'a, K, V> for MapView<'a, K, V> {
|
|
249
|
+
fn get(&self, k: &K) -> Option<&V> { self.inner.get(k).map(|b| &**b) }
|
|
250
|
+
fn len(&self) -> usize { self.inner.len() }
|
|
251
|
+
|
|
252
|
+
type Iter<'b> =
|
|
253
|
+
std::iter::Map<
|
|
254
|
+
std::collections::hash_map::Iter<'b, K, Box<V>>,
|
|
255
|
+
fn((&'b K,&'b Box<V>)) -> (&'b K,&'b V)
|
|
256
|
+
> where K: 'b, V: 'b, Self: 'b;
|
|
257
|
+
|
|
258
|
+
fn iter(&self) -> Self::Iter<'_> {
|
|
259
|
+
fn as_pair<'b, K, V>((k, v): (&'b K, &'b Box<V>)) -> (&'b K, &'b V) { (k, &**v) }
|
|
260
|
+
self.inner.iter().map(as_pair)
|
|
261
|
+
}
|
|
262
|
+
fn to_any(self) -> MapAny<'a, K, V>
|
|
263
|
+
where
|
|
264
|
+
Self: Sized
|
|
265
|
+
{
|
|
266
|
+
MapAny::View(MapView { inner : self.inner })
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
pub trait SeqRef<'l, T> {
|
|
273
|
+
/// Immutable iterator (`for x in seq.iter()`)
|
|
274
|
+
type Iter<'a>: Iterator<Item = &'a T> + ExactSizeIterator
|
|
275
|
+
where
|
|
276
|
+
Self: 'a,
|
|
277
|
+
T: 'a;
|
|
278
|
+
|
|
279
|
+
/// Number of elements
|
|
280
|
+
fn len(&self) -> usize;
|
|
281
|
+
|
|
282
|
+
/// Immutable indexing
|
|
283
|
+
fn get(&self, i: usize) -> Option<&T>;
|
|
284
|
+
|
|
285
|
+
/// Borrowing iterator
|
|
286
|
+
fn iter(&self) -> Self::Iter<'l>;
|
|
287
|
+
|
|
288
|
+
/// Convenience
|
|
289
|
+
fn is_empty(&self) -> bool { self.len() == 0 }
|
|
290
|
+
|
|
291
|
+
fn to_any(self) -> ListAny<'l, T>
|
|
292
|
+
where
|
|
293
|
+
Self: Sized;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
impl<'l, T> SeqRef<'l, T> for &'l Vec<T> {
|
|
298
|
+
type Iter<'a> = slice::Iter<'a, T> where T: 'a, Self: 'a;
|
|
299
|
+
|
|
300
|
+
fn len(&self) -> usize { Vec::len(self) }
|
|
301
|
+
fn get(&self, i: usize) -> Option<&T> { self.as_slice().get(i) }
|
|
302
|
+
fn iter(&self) -> Self::Iter<'l> { self.as_slice().iter() }
|
|
303
|
+
fn to_any(self) -> ListAny<'l, T>
|
|
304
|
+
where
|
|
305
|
+
Self: Sized,
|
|
306
|
+
{
|
|
307
|
+
ListAny::Vec(self)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
impl<'a, T> SeqRef<'a, T> for ListView<'a, T> {
|
|
313
|
+
type Iter<'b> = Iter<'b, T> where Self: 'b, T: 'b;
|
|
314
|
+
|
|
315
|
+
fn len(&self) -> usize { self.inner.len() }
|
|
316
|
+
fn get(&self, i: usize) -> Option<&T> { self.inner.get(i).map(debox) }
|
|
317
|
+
fn iter(&self) -> Self::Iter<'a> { self.inner.iter().map(debox) }
|
|
318
|
+
fn to_any(self) -> ListAny<'a, T>
|
|
319
|
+
where
|
|
320
|
+
Self: Sized,
|
|
321
|
+
{
|
|
322
|
+
ListAny::View(ListView { inner: self.inner })
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
pub enum MapAny<'a, K, V> {
|
|
327
|
+
Hash(&'a std::collections::HashMap<K, V>), // &HashMap
|
|
328
|
+
View(MapView<'a, K, V>), // MapView (already borrows)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
impl<'a, K: Eq + std::hash::Hash, V> MapRef<'a, K, V>
|
|
332
|
+
for MapAny<'a, K, V>
|
|
333
|
+
{
|
|
334
|
+
type Iter<'b> =
|
|
335
|
+
std::boxed::Box<dyn Iterator<Item = (&'b K, &'b V)> + 'b>
|
|
336
|
+
where Self: 'b, K: 'b, V: 'b;
|
|
337
|
+
|
|
338
|
+
fn len(&self) -> usize {
|
|
339
|
+
match self {
|
|
340
|
+
Self::Hash(m) => m.len(),
|
|
341
|
+
Self::View(v) => v.len(),
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
fn get(&self, k: &K) -> Option<&V> {
|
|
345
|
+
match self {
|
|
346
|
+
Self::Hash(m) => m.get(k),
|
|
347
|
+
Self::View(v) => v.get(k),
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
fn iter(&self) -> Self::Iter<'_> {
|
|
351
|
+
match self {
|
|
352
|
+
Self::Hash(m) => Box::new(m.iter()),
|
|
353
|
+
Self::View(v) => Box::new(v.iter()),
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
fn to_any(self) -> MapAny<'a, K, V>
|
|
357
|
+
where
|
|
358
|
+
Self: Sized,
|
|
359
|
+
{
|
|
360
|
+
match self {
|
|
361
|
+
Self::Hash(m) => MapAny::Hash(m),
|
|
362
|
+
Self::View(v) => MapAny::View(v),
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
pub enum ListIter<'a, T> {
|
|
369
|
+
Vec (std::slice::Iter<'a, T>),
|
|
370
|
+
View (ViewIter<'a, T>),
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
impl<'a, T> Iterator for ListIter<'a, T> {
|
|
374
|
+
type Item = &'a T;
|
|
375
|
+
fn next(&mut self) -> Option<Self::Item> {
|
|
376
|
+
match self {
|
|
377
|
+
Self::Vec(it) => it.next(),
|
|
378
|
+
Self::View(it) => it.next(),
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
382
|
+
match self {
|
|
383
|
+
Self::Vec(it) => it.size_hint(),
|
|
384
|
+
Self::View(it) => it.size_hint(),
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
impl<'a, T> ExactSizeIterator for ListIter<'a, T> {
|
|
390
|
+
fn len(&self) -> usize {
|
|
391
|
+
match self {
|
|
392
|
+
Self::Vec(it) => it.len(),
|
|
393
|
+
Self::View(it) => it.len(),
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
pub enum ListAny<'a, T> {
|
|
399
|
+
Vec(&'a Vec<T>), // &Vec<T>
|
|
400
|
+
View(ListView<'a, T>), // ListView (already borrows)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/* ------------------------------------------------------------------ *
|
|
404
|
+
* SeqRef implementation
|
|
405
|
+
* ------------------------------------------------------------------ */
|
|
406
|
+
impl<'a, T> SeqRef<'a, T> for ListAny<'a, T> {
|
|
407
|
+
type Iter<'x> = ListIter<'x, T> where Self: 'x, T: 'x;
|
|
408
|
+
//type Iter<'b> =
|
|
409
|
+
// std::boxed::Box<dyn Iterator<Item = &'b T> + ExactSizeIterator + 'b>
|
|
410
|
+
// where Self: 'b, T: 'b;
|
|
411
|
+
|
|
412
|
+
fn len(&self) -> usize {
|
|
413
|
+
match self {
|
|
414
|
+
Self::Vec(v) => v.len(),
|
|
415
|
+
Self::View(v) => v.len(),
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
fn get(&self, i: usize) -> Option<&T> {
|
|
419
|
+
match self {
|
|
420
|
+
Self::Vec(v) => v.get(i),
|
|
421
|
+
Self::View(v) => v.get(i),
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
fn iter(&self) -> Self::Iter<'a> {
|
|
425
|
+
match self {
|
|
426
|
+
Self::Vec(v) => ListIter::Vec(v.iter()),
|
|
427
|
+
Self::View(v) => ListIter::View(v.iter()),
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
fn to_any(self) -> ListAny<'a, T>
|
|
431
|
+
where
|
|
432
|
+
Self: Sized,
|
|
433
|
+
{
|
|
434
|
+
match self {
|
|
435
|
+
Self::Vec(v) => ListAny::Vec(v),
|
|
436
|
+
Self::View(v) => ListAny::View(v),
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pub trait {{ name}} {% if superclass_names | length > 0 %}:{% endif %}{% for n in superclass_names %} {{n}} {% if not loop.last %} + {% endif %}{%endfor %} {
|
|
2
|
+
|
|
3
|
+
{% for attr in attrs %}
|
|
4
|
+
{{ attr }}
|
|
5
|
+
{% endfor %}
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
{% for impl in impls %}
|
|
10
|
+
{{ impl }}
|
|
11
|
+
{% endfor %}
|
|
12
|
+
|
|
13
|
+
{% for st in subtypes %}
|
|
14
|
+
{{ st }}
|
|
15
|
+
{% endfor %}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{% set lifetime_needed = needs_lifetime %}
|
|
2
|
+
fn {{ name }}{% if lifetime_needed %}<'a>{% endif %}(&{% if lifetime_needed %}'a {% endif %}self) -> {{ type_getter }};
|
|
3
|
+
// fn {{ name }}_mut(&mut self) -> &mut {{ type_getter }};
|
|
4
|
+
{% if type_bound %}
|
|
5
|
+
// fn set_{{ name }}<E>(&mut self, value: {{ type_setter }}) where E: {{ type_bound }};
|
|
6
|
+
{% else %}
|
|
7
|
+
// fn set_{{ name }}(&mut self, value: {{ type_setter }});
|
|
8
|
+
{% endif %}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
{% set lifetime_needed = range.containerType %}
|
|
2
|
+
{% set lifetime_needed = needs_lifetime %}
|
|
3
|
+
fn {{ name}}{% if lifetime_needed %}<'a>{% endif %}(&{% if lifetime_needed %}'a {% endif %}self) -> {{ type_getter }} {
|
|
4
|
+
{% if definition_range.child_ranges %}
|
|
5
|
+
{% set u = union_type %}
|
|
6
|
+
{% if ct == 'list' %}
|
|
7
|
+
{% if range.optional %}
|
|
8
|
+
self.{{ name }}.as_ref().map(|xs| {% if range.child_ranges and current_union_type == union_type %}xs.clone(){% else %}xs.iter().map(|v| {% if range.child_ranges %}v.clone(){% else %}{{ u }}::{{ range_variant }}(v.clone()){%- endif -%}).collect(){% endif %})
|
|
9
|
+
{% else %}
|
|
10
|
+
{% if range.child_ranges and current_union_type == union_type %}
|
|
11
|
+
self.{{ name }}.clone()
|
|
12
|
+
{% else %}
|
|
13
|
+
self.{{ name }}.iter().map(|v| {% if range.child_ranges %}v.clone(){% else %}{{ u }}::{{ range_variant }}(v.clone()){%- endif -%}).collect()
|
|
14
|
+
{% endif %}
|
|
15
|
+
{% endif %}
|
|
16
|
+
{% elif ct == "mapping" %}
|
|
17
|
+
{% if range.optional %}
|
|
18
|
+
self.{{ name}}
|
|
19
|
+
.as_ref()
|
|
20
|
+
.map(|m| {% if range.child_ranges and current_union_type == union_type %}m.clone(){% else %}m.iter().map(|(k,v)| (k.clone(), {% if range.child_ranges %}v.clone(){% else %}{{ u }}::{{ range_variant }}(v.clone()){%- endif -%})).collect(){% endif %})
|
|
21
|
+
{% else %}
|
|
22
|
+
{% if range.child_ranges and current_union_type == union_type %}
|
|
23
|
+
self.{{ name }}.clone()
|
|
24
|
+
{% else %}
|
|
25
|
+
self.{{ name }}.iter().map(|(k,v)| (k.clone(), {% if range.child_ranges %}v.clone(){% else %}{{ u }}::{{ range_variant }}(v.clone()){%- endif -%})).collect()
|
|
26
|
+
{% endif %}
|
|
27
|
+
{% endif %}
|
|
28
|
+
{% else %}
|
|
29
|
+
{% if definition_range.optional %}
|
|
30
|
+
{% if range.optional %}
|
|
31
|
+
{% if range.child_ranges %}
|
|
32
|
+
{% if current_union_type == union_type %}
|
|
33
|
+
self.{{ name }}.as_ref().cloned()
|
|
34
|
+
{% else %}
|
|
35
|
+
self.{{ name }}.as_ref().map(|v| match v {
|
|
36
|
+
{% for arm in union_conversion_arms %}
|
|
37
|
+
{{ arm }}
|
|
38
|
+
{% endfor %}
|
|
39
|
+
})
|
|
40
|
+
{% endif %}
|
|
41
|
+
{% else %}
|
|
42
|
+
self.{{ name }}.as_ref().map(|v| {{ u }}::{{ range_variant }}(v.clone()))
|
|
43
|
+
{% endif %}
|
|
44
|
+
{% else %}
|
|
45
|
+
{% if range.child_ranges %}
|
|
46
|
+
{% if current_union_type == union_type %}
|
|
47
|
+
Some(self.{{ name }}.clone())
|
|
48
|
+
{% else %}
|
|
49
|
+
Some(match &self.{{ name }} {
|
|
50
|
+
{% for arm in union_conversion_arms %}
|
|
51
|
+
{{ arm }}
|
|
52
|
+
{% endfor %}
|
|
53
|
+
})
|
|
54
|
+
{% endif %}
|
|
55
|
+
{% else %}
|
|
56
|
+
Some({{ u }}::{{ range_variant }}(self.{{ name }}.clone()))
|
|
57
|
+
{% endif %}
|
|
58
|
+
{% endif %}
|
|
59
|
+
{% else %}
|
|
60
|
+
{% if range.child_ranges %}
|
|
61
|
+
{% if current_union_type == union_type %}
|
|
62
|
+
self.{{ name }}.clone()
|
|
63
|
+
{% else %}
|
|
64
|
+
match &self.{{ name }} {
|
|
65
|
+
{% for arm in union_conversion_arms %}
|
|
66
|
+
{{ arm }}
|
|
67
|
+
{% endfor %}
|
|
68
|
+
}
|
|
69
|
+
{% endif %}
|
|
70
|
+
{% else %}
|
|
71
|
+
{{ u }}::{{ range_variant }}(self.{{ name }}.clone())
|
|
72
|
+
{% endif %}
|
|
73
|
+
{% endif %}
|
|
74
|
+
{% endif %}
|
|
75
|
+
{% else %}
|
|
76
|
+
{% if range.box_needed %}
|
|
77
|
+
{% if ct == 'list' %}
|
|
78
|
+
{% if range.optional %}
|
|
79
|
+
return self.{{ name }}.as_ref().map(|x| poly_containers::ListView::new(x));
|
|
80
|
+
{% else %}
|
|
81
|
+
return poly_containers::ListView::new(&self.{{ name }});
|
|
82
|
+
{% endif %}
|
|
83
|
+
{% elif ct == "mapping" %}
|
|
84
|
+
{% if range.optional %}
|
|
85
|
+
return self.{{ name}}
|
|
86
|
+
.as_ref()
|
|
87
|
+
.map(poly_containers::MapView::new);
|
|
88
|
+
{% else %}
|
|
89
|
+
return poly_containers::MapView::new(&self.{{ name }});
|
|
90
|
+
{% endif %}
|
|
91
|
+
{% else %}
|
|
92
|
+
{% if is_copy %}
|
|
93
|
+
return self.{{ name }};
|
|
94
|
+
{% else %}
|
|
95
|
+
return self.{{ name }}.as_deref();
|
|
96
|
+
{% endif %}
|
|
97
|
+
{% endif %}
|
|
98
|
+
{% else %}
|
|
99
|
+
{% if range.optional %}
|
|
100
|
+
{% if type_getter == 'Option<&str>' or type_getter == "Option<&'a str>" %}
|
|
101
|
+
return self.{{ name }}.as_deref();
|
|
102
|
+
{% elif type_getter == 'Option<String>' %}
|
|
103
|
+
return self.{{ name }}.as_ref().map(|x| x.to_string());
|
|
104
|
+
{% elif ct != 'list' and ct != 'mapping' %}
|
|
105
|
+
{% if is_copy %}
|
|
106
|
+
return self.{{ name }};
|
|
107
|
+
{% else %}
|
|
108
|
+
return self.{{ name }}.as_ref();
|
|
109
|
+
{% endif %}
|
|
110
|
+
{% else %}
|
|
111
|
+
return self.{{ name }}.as_ref();
|
|
112
|
+
{% endif %}
|
|
113
|
+
{% else %}
|
|
114
|
+
{% if need_option_wrap %}
|
|
115
|
+
{% if type_getter == 'Option<String>' %}
|
|
116
|
+
return Some(self.{{ name }}.to_string());
|
|
117
|
+
{% else %}
|
|
118
|
+
return Some(&self.{{ name }});
|
|
119
|
+
{% endif %}
|
|
120
|
+
{% else %}
|
|
121
|
+
{% if is_copy %}
|
|
122
|
+
return self.{{ name }};
|
|
123
|
+
{% elif type_getter == "&'a str" or type_getter == "&str" %}
|
|
124
|
+
return &self.{{ name }}[..];
|
|
125
|
+
{% else %}
|
|
126
|
+
return &self.{{ name }};
|
|
127
|
+
{% endif %}
|
|
128
|
+
{% endif %}
|
|
129
|
+
{% endif %}
|
|
130
|
+
{% endif %}
|
|
131
|
+
{% endif %}
|
|
132
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{% set lifetime_needed = range.containerType %}
|
|
2
|
+
{% set lifetime_needed = needs_lifetime %}
|
|
3
|
+
fn {{ name}}{% if lifetime_needed %}<'a>{% endif %}(&{% if lifetime_needed %}'a {% endif %}self) -> {{ type_getter }} {
|
|
4
|
+
match self {
|
|
5
|
+
{% for c in cases %}
|
|
6
|
+
{{ struct_name }}::{{c}}(val) => val.{{name}}(){% if is_container %}{% if is_optional %}.map(|x| x.to_any()){% else %}.to_any(){% endif %}{% endif %},
|
|
7
|
+
{% endfor %}
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{% if generate_merge %}
|
|
2
|
+
#[merge({{ merge_strategy }})]
|
|
3
|
+
{% endif %}
|
|
4
|
+
{%- if is_key_value -%}
|
|
5
|
+
{% if container_mode == "list" and inline_mode == "inline" %}
|
|
6
|
+
#[cfg_attr(feature = "serde", serde(deserialize_with = "serde_utils::deserialize_inlined_dict_list{% if optional %}_optional{% endif %}{% if recursive %}_box{% endif %}"))]
|
|
7
|
+
{% elif container_mode == "mapping" and inline_mode == "inline" %}
|
|
8
|
+
#[cfg_attr(feature = "serde", serde(deserialize_with = "serde_utils::deserialize_inlined_dict_map{% if optional %}_optional{% endif %}{% if recursive %}_box{% endif %}"))]
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% elif container_mode == "list" and inline_mode == "primitive" %}
|
|
11
|
+
#[cfg_attr(feature = "serde", serde(deserialize_with = "serde_utils::deserialize_primitive_list_or_single_value{% if optional %}_optional{% endif %}"))]
|
|
12
|
+
{% endif -%}
|
|
13
|
+
{% if hasdefault %}
|
|
14
|
+
#[cfg_attr(feature = "serde", serde(default))]
|
|
15
|
+
{% endif %}
|
|
16
|
+
{% if alias %}
|
|
17
|
+
#[cfg_attr(feature = "serde", serde(alias = "{{ alias }}"))]
|
|
18
|
+
{% endif %}
|
|
19
|
+
pub {{ name }}: {{ type_for_field }}
|