archunit/layers/fluentapi/
layers.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
45
46
47
48
49
50
51
52
use std::path::PathBuf;

use crate::common::ProjectLocator;

use super::LayeredArchitecture;

/// Starts a named-layer architecture policy using automatic Cargo project discovery.
pub fn project_layers() -> LayeredArchitecture {
    LayeredArchitecture::new(ProjectLocator::auto_detect())
}

/// Alias for [`project_layers`].
pub fn layers() -> LayeredArchitecture {
    project_layers()
}

/// Starts a named-layer policy at an explicit directory or `Cargo.toml` manifest.
pub fn project_layers_in(path: impl Into<PathBuf>) -> LayeredArchitecture {
    LayeredArchitecture::new(ProjectLocator::from_path(path))
}

/// Alias for [`project_layers_in`].
pub fn layers_in(path: impl Into<PathBuf>) -> LayeredArchitecture {
    project_layers_in(path)
}

#[cfg(test)]
mod tests {
    use std::path::Path;

    use super::{layers, layers_in, project_layers, project_layers_in};

    #[test]
    fn default_entry_points_request_auto_detection() {
        assert!(project_layers().project_locator().path().is_none());
        assert!(layers().project_locator().path().is_none());
    }

    #[test]
    fn explicit_entry_points_own_the_starting_path() {
        assert_eq!(
            project_layers_in("examples/layered")
                .project_locator()
                .path(),
            Some(Path::new("examples/layered"))
        );
        assert_eq!(
            layers_in("examples/aliased").project_locator().path(),
            Some(Path::new("examples/aliased"))
        );
    }
}