augr_core/store/
meta.rs

1use crate::PatchRef;
2use serde::{Deserialize, Serialize};
3
4type Set<T> = std::collections::HashSet<T>;
5
6#[derive(Default, Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "kebab-case")]
8pub struct Meta {
9    /// The patches that this Meta file depends on, which may exclude patches
10    /// that are referenced as ancestors of some patch that is included.
11    patches: Set<PatchRef>,
12}
13
14impl Meta {
15    pub fn new() -> Self {
16        Self {
17            patches: Set::new(),
18        }
19    }
20
21    pub fn add_patch(&mut self, patch_ref: PatchRef) {
22        self.patches.insert(patch_ref);
23    }
24
25    pub fn patches(&self) -> impl Iterator<Item = &PatchRef> {
26        self.patches.iter()
27    }
28}
29
30#[cfg(test)]
31mod test {
32    use super::*;
33    use uuid::Uuid;
34
35    #[test]
36    fn read_from_toml() {
37        let expected = Meta {
38            patches: [
39                "c10350e8-3f30-4d27-b120-8ee079e256d9",
40                "7a826905-7a3e-430d-9d54-5af08ecb482c",
41            ]
42            .into_iter()
43            .map(|s| Uuid::parse_str(s).unwrap())
44            .collect(),
45        };
46        let toml_str = r#"
47            patches = ["c10350e8-3f30-4d27-b120-8ee079e256d9", "7a826905-7a3e-430d-9d54-5af08ecb482c"]
48        "#;
49        assert_eq!(toml::de::from_str(toml_str), Ok(expected));
50    }
51
52}