use xuanji::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 in_crate(package: &str) -> ForbiddenMarkerCrateDraft {
ForbiddenMarkerCrateDraft {
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 struct ForbiddenMarkerCrateDraft {
crate_package: String,
}
impl ForbiddenMarkerCrateDraft {
pub fn module(self, module: &str) -> ForbiddenMarkerModuleDraft {
ForbiddenMarkerModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
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,
}
}
}
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 warn(mut self) -> Self {
self.severity = Severity::Warn;
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,
}
}
}