archunit/files/fluentapi/
files.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::FileConditionBuilder;

/// Starts a file architecture rule using automatic Cargo project discovery.
pub fn project_files() -> FileConditionBuilder {
    FileConditionBuilder::new(ProjectLocator::auto_detect())
}

/// Alias for [`project_files`].
pub fn files() -> FileConditionBuilder {
    project_files()
}

/// Starts a file architecture rule at an explicit directory or `Cargo.toml` manifest.
pub fn project_files_in(path: impl Into<PathBuf>) -> FileConditionBuilder {
    FileConditionBuilder::new(ProjectLocator::from_path(path))
}

/// Alias for [`project_files_in`].
pub fn files_in(path: impl Into<PathBuf>) -> FileConditionBuilder {
    project_files_in(path)
}

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

    use super::{files, files_in, project_files, project_files_in};

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

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