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
use std::collections::HashMap;

include!(concat!(env!("OUT_DIR"), "/lwjson.rs"));

pub trait HelperMethods {
    fn build_repo_map(&self) -> HashMap<&str, &Repository>;
    fn build_artifacts_map(&self) -> HashMap<&str, &Artifact>;
}

impl HelperMethods for Document {
    fn build_repo_map(&self) -> HashMap<&str, &Repository> {
        let mut result = HashMap::new();
        for repositories in &self.repositories {
            for repo in repositories {
                result.insert(repo.id.as_str(), repo);
            }
        }
        result
    }

    fn build_artifacts_map(&self) -> HashMap<&str, &Artifact> {
        let mut result = HashMap::new();
        for artifacts in &self.artifacts {
            for artifact in artifacts {
                result.insert(artifact.id.as_str(), artifact);
            }
        }
        result
    }
}