archunit/common/extraction/
source_options.rs

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
42
43
44
/// Options that change Cargo source discovery.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[non_exhaustive]
pub struct SourceOptions {
    include_dev_targets: bool,
}

impl SourceOptions {
    /// Creates the production-target-only source configuration.
    #[must_use]
    pub const fn new() -> Self {
        Self {
            include_dev_targets: false,
        }
    }

    /// Returns whether Cargo test, example, and benchmark targets are included.
    #[must_use]
    pub const fn includes_dev_targets(self) -> bool {
        self.include_dev_targets
    }

    /// Controls whether Cargo test, example, and benchmark targets are included.
    #[must_use]
    pub const fn with_dev_targets(mut self, include: bool) -> Self {
        self.include_dev_targets = include;
        self
    }
}

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

    #[test]
    fn development_targets_are_opt_in() {
        assert!(!SourceOptions::default().includes_dev_targets());
        assert!(
            SourceOptions::new()
                .with_dev_targets(true)
                .includes_dev_targets()
        );
    }
}