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

/// # `Accessed` may only be accessed by `accessors` relation
/// This access rule relation states that the `accessors` layers may only access the specified `accessed` layer.
/// As layer name it attempts to match either the module name or the parent module name, which is the directory the files were placed in.
/// If `when_same_parent` is `true`, the access rule is only applied within the same scope of modules that share the same parent.
#[derive(Debug, Clone)]
pub struct MayOnlyBeAccessedBy {
    accessors: HashSet<String>,
    accessed: String,
    when_same_parent: bool,
}

impl MayOnlyBeAccessedBy {
    pub fn new(accessed: String, accessor_layers: HashSet<String>, when_same_parent: bool) -> Self {
        MayOnlyBeAccessedBy {
            accessors: accessor_layers,
            accessed,
            when_same_parent,
        }
    }

    pub fn accessors(&self) -> &HashSet<String> {
        &self.accessors
    }

    pub fn accessed(&self) -> &String {
        &self.accessed
    }

    pub fn when_same_parent(&self) -> bool {
        self.when_same_parent
    }
}