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
/*
    Appellation: utils <module>
    Creator: FL03 <jo3mccain@icloud.com>
    Description:
        ... Summary ...
*/

// Gather configuration files following the specified pattern and collect them into a vector
pub fn collect_config_files(pattern: &str, required: bool) -> crate::ConfigFileVec {
    glob::glob(pattern)
        .unwrap()
        .map(|path| crate::ConfigFile::from(path.unwrap()).required(required))
        .collect::<Vec<_>>()
}

/// Consolidate resources required for generating random numbers
pub fn random_number<T>() -> T
where
    rand::distributions::Standard: rand::prelude::Distribution<T>,
{
    use rand::Rng;
    let mut rnd = rand::thread_rng();
    rnd.gen::<T>()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_collect_config_files() {
        let actual = collect_config_files("**/*.config.*", false);
        let expected = actual.clone().len();
        assert_eq!(actual.len(), expected)
    }

    #[test]
    fn test_random_number() {
        assert_ne!(random_number::<f64>(), random_number::<f64>())
    }
}