use xuanji::Severity;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SemanticBoundary {
pub(crate) crate_package: String,
pub(crate) module: String,
pub(crate) forbidden: Vec<String>,
pub(crate) reason: String,
pub(crate) anchor: Option<String>,
pub(crate) severity: Severity,
pub(crate) including_trait_impls: bool,
}
impl SemanticBoundary {
pub fn in_crate(package: &str) -> SemanticCrateDraft {
SemanticCrateDraft {
crate_package: package.to_string(),
}
}
pub fn crate_package(&self) -> &str {
&self.crate_package
}
pub fn module(&self) -> &str {
&self.module
}
pub fn forbidden(&self) -> &[String] {
&self.forbidden
}
pub fn reason(&self) -> &str {
&self.reason
}
pub fn with_anchor(mut self, anchor: &str) -> Self {
self.anchor = Some(anchor.to_string());
self
}
pub fn anchor(&self) -> Option<&str> {
self.anchor.as_deref()
}
pub fn severity(&self) -> Severity {
self.severity
}
pub fn including_trait_impls(&self) -> bool {
self.including_trait_impls
}
}
pub struct SemanticCrateDraft {
crate_package: String,
}
impl SemanticCrateDraft {
pub fn module(self, module: &str) -> SemanticModuleDraft {
SemanticModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
pub struct SemanticModuleDraft {
crate_package: String,
module: String,
}
impl SemanticModuleDraft {
pub fn must_not_expose(self, path: &str) -> SemanticBoundaryDraft {
SemanticBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
forbidden: vec![path.to_string()],
severity: Severity::Enforce,
including_trait_impls: false,
}
}
}
pub struct SemanticBoundaryDraft {
crate_package: String,
module: String,
forbidden: Vec<String>,
severity: Severity,
including_trait_impls: bool,
}
impl SemanticBoundaryDraft {
pub fn and_not_expose(mut self, path: &str) -> Self {
self.forbidden.push(path.to_string());
self
}
pub fn warn(mut self) -> Self {
self.severity = Severity::Warn;
self
}
pub fn including_trait_impls(mut self) -> Self {
self.including_trait_impls = true;
self
}
pub fn because(self, reason: &str) -> SemanticBoundary {
SemanticBoundary {
crate_package: self.crate_package,
module: self.module,
forbidden: self.forbidden,
reason: reason.to_string(),
anchor: None,
severity: self.severity,
including_trait_impls: self.including_trait_impls,
}
}
}