use xuanji::{RuleKey, Severity};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ForbiddenMarkerBoundary {
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,
}
impl ForbiddenMarkerBoundary {
pub fn rule_key(&self) -> RuleKey {
RuleKey::of(
"tianheng.rule/hunyi/forbidden-marker",
[("forbidden", super::canonical_path_set(&self.forbidden))],
)
}
pub fn in_crate(package: &str) -> ForbiddenMarkerCrateDraft {
ForbiddenMarkerCrateDraft {
crate_package: package.to_string(),
}
}
pub fn module(&self) -> &str {
&self.module
}
pub fn forbidden(&self) -> &[String] {
&self.forbidden
}
pub fn reason(&self) -> &str {
&self.reason
}
}
crate::dsl::boundary_common!(ForbiddenMarkerBoundary, ForbiddenMarkerBoundaryDraft);
#[doc(hidden)]
pub struct ForbiddenMarkerCrateDraft {
crate_package: String,
}
impl ForbiddenMarkerCrateDraft {
pub fn module(self, module: &str) -> ForbiddenMarkerModuleDraft {
ForbiddenMarkerModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
#[doc(hidden)]
pub struct ForbiddenMarkerModuleDraft {
crate_package: String,
module: String,
}
impl ForbiddenMarkerModuleDraft {
pub fn must_not_acquire(self, trait_path: &str) -> ForbiddenMarkerBoundaryDraft {
ForbiddenMarkerBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
forbidden: vec![trait_path.to_string()],
severity: Severity::Enforce,
}
}
}
#[doc(hidden)]
pub struct ForbiddenMarkerBoundaryDraft {
crate_package: String,
module: String,
forbidden: Vec<String>,
severity: Severity,
}
impl ForbiddenMarkerBoundaryDraft {
pub fn and_not_acquire(mut self, trait_path: &str) -> Self {
self.forbidden.push(trait_path.to_string());
self
}
pub fn because(self, reason: &str) -> ForbiddenMarkerBoundary {
ForbiddenMarkerBoundary {
crate_package: self.crate_package,
module: self.module,
forbidden: self.forbidden,
reason: reason.to_string(),
anchor: None,
severity: self.severity,
}
}
}