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) 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 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(),
severity: self.severity,
including_trait_impls: self.including_trait_impls,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TraitImplBoundary {
pub(crate) crate_package: String,
pub(crate) trait_path: String,
pub(crate) allowed_locations: Vec<String>,
pub(crate) reason: String,
pub(crate) severity: Severity,
}
impl TraitImplBoundary {
pub fn in_crate(package: &str) -> TraitImplCrateDraft {
TraitImplCrateDraft {
crate_package: package.to_string(),
}
}
pub fn crate_package(&self) -> &str {
&self.crate_package
}
pub fn trait_(&self) -> &str {
&self.trait_path
}
pub fn allowed_locations(&self) -> &[String] {
&self.allowed_locations
}
pub fn reason(&self) -> &str {
&self.reason
}
pub fn severity(&self) -> Severity {
self.severity
}
}
pub struct TraitImplCrateDraft {
crate_package: String,
}
impl TraitImplCrateDraft {
pub fn trait_(self, trait_path: &str) -> TraitImplTraitDraft {
TraitImplTraitDraft {
crate_package: self.crate_package,
trait_path: trait_path.to_string(),
}
}
}
pub struct TraitImplTraitDraft {
crate_package: String,
trait_path: String,
}
impl TraitImplTraitDraft {
pub fn only_implemented_in(self, location: &str) -> TraitImplBoundaryDraft {
TraitImplBoundaryDraft {
crate_package: self.crate_package,
trait_path: self.trait_path,
allowed_locations: vec![location.to_string()],
severity: Severity::Enforce,
}
}
}
pub struct TraitImplBoundaryDraft {
crate_package: String,
trait_path: String,
allowed_locations: Vec<String>,
severity: Severity,
}
impl TraitImplBoundaryDraft {
pub fn and_in(mut self, location: &str) -> Self {
self.allowed_locations.push(location.to_string());
self
}
pub fn warn(mut self) -> Self {
self.severity = Severity::Warn;
self
}
pub fn because(self, reason: &str) -> TraitImplBoundary {
TraitImplBoundary {
crate_package: self.crate_package,
trait_path: self.trait_path,
allowed_locations: self.allowed_locations,
reason: reason.to_string(),
severity: self.severity,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VisibilityBoundary {
pub(crate) crate_package: String,
pub(crate) module: String,
pub(crate) reason: String,
pub(crate) severity: Severity,
}
impl VisibilityBoundary {
pub fn in_crate(package: &str) -> VisibilityCrateDraft {
VisibilityCrateDraft {
crate_package: package.to_string(),
}
}
pub fn crate_package(&self) -> &str {
&self.crate_package
}
pub fn module(&self) -> &str {
&self.module
}
pub fn reason(&self) -> &str {
&self.reason
}
pub fn severity(&self) -> Severity {
self.severity
}
}
pub struct VisibilityCrateDraft {
crate_package: String,
}
impl VisibilityCrateDraft {
pub fn module(self, module: &str) -> VisibilityModuleDraft {
VisibilityModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
pub struct VisibilityModuleDraft {
crate_package: String,
module: String,
}
impl VisibilityModuleDraft {
pub fn must_not_declare_pub(self) -> VisibilityBoundaryDraft {
VisibilityBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
severity: Severity::Enforce,
}
}
}
pub struct VisibilityBoundaryDraft {
crate_package: String,
module: String,
severity: Severity,
}
impl VisibilityBoundaryDraft {
pub fn warn(mut self) -> Self {
self.severity = Severity::Warn;
self
}
pub fn because(self, reason: &str) -> VisibilityBoundary {
VisibilityBoundary {
crate_package: self.crate_package,
module: self.module,
reason: reason.to_string(),
severity: self.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) 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 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(),
severity: self.severity,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DynTraitBoundary {
pub(crate) crate_package: String,
pub(crate) module: String,
pub(crate) forbidden_operands: Vec<String>,
pub(crate) reason: String,
pub(crate) severity: Severity,
}
impl DynTraitBoundary {
pub fn in_crate(package: &str) -> DynTraitCrateDraft {
DynTraitCrateDraft {
crate_package: package.to_string(),
}
}
pub fn crate_package(&self) -> &str {
&self.crate_package
}
pub fn module(&self) -> &str {
&self.module
}
pub fn forbidden_operands(&self) -> &[String] {
&self.forbidden_operands
}
pub fn reason(&self) -> &str {
&self.reason
}
pub fn severity(&self) -> Severity {
self.severity
}
}
pub struct DynTraitCrateDraft {
crate_package: String,
}
impl DynTraitCrateDraft {
pub fn module(self, module: &str) -> DynTraitModuleDraft {
DynTraitModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
pub struct DynTraitModuleDraft {
crate_package: String,
module: String,
}
impl DynTraitModuleDraft {
pub fn must_not_expose_dyn(self) -> DynTraitBoundaryDraft {
DynTraitBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
forbidden_operands: Vec::new(),
severity: Severity::Enforce,
}
}
pub fn must_not_expose_dyn_of<I, S>(self, operands: I) -> DynTraitBoundaryDraft
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
DynTraitBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
forbidden_operands: operands.into_iter().map(Into::into).collect(),
severity: Severity::Enforce,
}
}
}
pub struct DynTraitBoundaryDraft {
crate_package: String,
module: String,
forbidden_operands: Vec<String>,
severity: Severity,
}
impl DynTraitBoundaryDraft {
pub fn warn(mut self) -> Self {
self.severity = Severity::Warn;
self
}
pub fn because(self, reason: &str) -> DynTraitBoundary {
DynTraitBoundary {
crate_package: self.crate_package,
module: self.module,
forbidden_operands: self.forbidden_operands,
reason: reason.to_string(),
severity: self.severity,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ImplTraitBoundary {
pub(crate) crate_package: String,
pub(crate) module: String,
pub(crate) forbidden_operands: Vec<String>,
pub(crate) reason: String,
pub(crate) severity: Severity,
}
impl ImplTraitBoundary {
pub fn in_crate(package: &str) -> ImplTraitCrateDraft {
ImplTraitCrateDraft {
crate_package: package.to_string(),
}
}
pub fn crate_package(&self) -> &str {
&self.crate_package
}
pub fn module(&self) -> &str {
&self.module
}
pub fn forbidden_operands(&self) -> &[String] {
&self.forbidden_operands
}
pub fn reason(&self) -> &str {
&self.reason
}
pub fn severity(&self) -> Severity {
self.severity
}
}
pub struct ImplTraitCrateDraft {
crate_package: String,
}
impl ImplTraitCrateDraft {
pub fn module(self, module: &str) -> ImplTraitModuleDraft {
ImplTraitModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
pub struct ImplTraitModuleDraft {
crate_package: String,
module: String,
}
impl ImplTraitModuleDraft {
pub fn must_not_expose_impl_trait(self) -> ImplTraitBoundaryDraft {
ImplTraitBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
forbidden_operands: Vec::new(),
severity: Severity::Enforce,
}
}
pub fn must_not_expose_impl_trait_of<I, S>(self, operands: I) -> ImplTraitBoundaryDraft
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
ImplTraitBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
forbidden_operands: operands.into_iter().map(Into::into).collect(),
severity: Severity::Enforce,
}
}
}
pub struct ImplTraitBoundaryDraft {
crate_package: String,
module: String,
forbidden_operands: Vec<String>,
severity: Severity,
}
impl ImplTraitBoundaryDraft {
pub fn warn(mut self) -> Self {
self.severity = Severity::Warn;
self
}
pub fn because(self, reason: &str) -> ImplTraitBoundary {
ImplTraitBoundary {
crate_package: self.crate_package,
module: self.module,
forbidden_operands: self.forbidden_operands,
reason: reason.to_string(),
severity: self.severity,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AsyncExposureBoundary {
pub(crate) crate_package: String,
pub(crate) module: String,
pub(crate) reason: String,
pub(crate) severity: Severity,
}
impl AsyncExposureBoundary {
pub fn in_crate(package: &str) -> AsyncExposureCrateDraft {
AsyncExposureCrateDraft {
crate_package: package.to_string(),
}
}
pub fn crate_package(&self) -> &str {
&self.crate_package
}
pub fn module(&self) -> &str {
&self.module
}
pub fn reason(&self) -> &str {
&self.reason
}
pub fn severity(&self) -> Severity {
self.severity
}
}
pub struct AsyncExposureCrateDraft {
crate_package: String,
}
impl AsyncExposureCrateDraft {
pub fn module(self, module: &str) -> AsyncExposureModuleDraft {
AsyncExposureModuleDraft {
crate_package: self.crate_package,
module: module.to_string(),
}
}
}
pub struct AsyncExposureModuleDraft {
crate_package: String,
module: String,
}
impl AsyncExposureModuleDraft {
pub fn must_not_expose_async_fn(self) -> AsyncExposureBoundaryDraft {
AsyncExposureBoundaryDraft {
crate_package: self.crate_package,
module: self.module,
severity: Severity::Enforce,
}
}
}
pub struct AsyncExposureBoundaryDraft {
crate_package: String,
module: String,
severity: Severity,
}
impl AsyncExposureBoundaryDraft {
pub fn warn(mut self) -> Self {
self.severity = Severity::Warn;
self
}
pub fn because(self, reason: &str) -> AsyncExposureBoundary {
AsyncExposureBoundary {
crate_package: self.crate_package,
module: self.module,
reason: reason.to_string(),
severity: self.severity,
}
}
}