1use substrate_data::schema::Found;
6use substrate_data::{Kind, Path, Ref};
7
8use crate::{Meaning, Res, kinds};
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct TagRef {
13 pub kind: String,
14 pub id: String,
15}
16
17pub fn content(refs: &[Found<Ref>]) -> impl Iterator<Item = &Found<Ref>> {
20 let domain = [
21 kinds::Tag::NAME,
22 kinds::Res::NAME,
23 kinds::Lang::NAME,
24 kinds::Image::NAME,
25 ];
26 refs.iter()
27 .filter(move |f| !domain.contains(&f.value.kind.as_str()))
28}
29
30pub fn tags(refs: &[Found<Ref>]) -> Vec<Found<TagRef>> {
32 meanings(refs)
33 .filter_map(|(m, path)| match m {
34 Meaning::Tag(value) => Some(Found { value, path }),
35 _ => None,
36 })
37 .collect()
38}
39
40pub fn resources(refs: &[Found<Ref>]) -> Vec<Found<Res>> {
42 meanings(refs)
43 .filter_map(|(m, path)| match m {
44 Meaning::Res(value) => Some(Found { value, path }),
45 _ => None,
46 })
47 .collect()
48}
49
50fn meanings(refs: &[Found<Ref>]) -> impl Iterator<Item = (Meaning, Path)> + '_ {
52 refs.iter()
53 .filter_map(|f| Some((Meaning::of(f.value.clone())?, f.path.clone())))
54}