mod error;
mod graph;
mod path;
mod rule;
mod scanner;
mod violation;
pub use crate::error::ArchavenError;
pub use crate::graph::{Dependency, DependencyGraph, Location, SourceDirectory};
pub use crate::path::{ModulePath, PathPattern, PrefixMatch};
pub use crate::rule::{Access, Rule, RuleSet};
pub use crate::violation::{Violation, Violations};
use std::path::Path;
#[derive(Default)]
pub struct Archaven {
rules: Vec<Box<dyn RuleSet>>,
}
impl Archaven {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn rule<R>(mut self, rule: R) -> Self
where
R: RuleSet + 'static,
{
self.rules.push(Box::new(rule));
self
}
pub fn check(&self, root: impl AsRef<Path>) -> Result<Violations, ArchavenError> {
let graph = scanner::scan(root.as_ref())?;
let mut violations = Violations::new();
for rule in &self.rules {
violations.extend(rule.check(&graph)?);
}
Ok(violations)
}
}