use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Law {
Zone,
Seal,
Keep,
Cycle,
Reach,
Use,
Escape,
}
impl Law {
pub const ALL: [Self; 7] =
[Self::Zone, Self::Seal, Self::Keep, Self::Cycle, Self::Reach, Self::Use, Self::Escape];
pub const NAMES: [&'static str; 7] =
["zone", "seal", "keep", "cycle", "reach", "use", "escape"];
#[must_use]
pub fn as_str(self) -> &'static str {
Self::NAMES[self as usize]
}
#[must_use]
pub fn parse(name: &str) -> Option<Self> {
Self::NAMES.iter().position(|n| *n == name).map(|i| Self::ALL[i])
}
#[must_use]
pub fn remedy(self) -> &'static str {
match self {
Self::Zone => {
"Move the dependency down the stack, or ratify the edge with \
`variance zone … because \"…\"`."
}
Self::Seal => {
"Re-export what the caller needs from the seal's entry file, or widen \
that seal's `open to` list."
}
Self::Keep => {
"Move the shared declaration down to a module both sides already stand \
on — widening the guest list is how a peer boundary dissolves."
}
Self::Cycle => {
"Break the cycle by moving the shared declaration into a lower zone \
both sides may depend on."
}
Self::Reach => {
"Move the file nearer what it depends on, or lower `limit reach` \
deliberately (it is a ceiling you lower, never raise to go green)."
}
Self::Use => {
"Grant it with `use <module> by <zone>`, or take the dependency in a \
zone that already carries it — the point of the grant is that a new \
outside dependency is a decision somebody makes, not one an import \
makes quietly."
}
Self::Escape => "Declare the cross-module dependency as a named module in the build.",
}
}
}
impl fmt::Display for Law {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}