use crate::score::Score;
macro_rules! anchors {
(
$(#[$meta:meta])* $name:ident {
$($(#[$vmeta:meta])* $variant:ident => $value:literal),* $(,)?
}
) => {
$(#[$meta])*
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum $name {
$($(#[$vmeta])* $variant),*
}
impl $name {
#[must_use]
pub const fn score(self) -> Score {
match self {
$(Self::$variant => Score::lit($value)),*
}
}
}
impl From<$name> for Score {
fn from(anchor: $name) -> Self {
anchor.score()
}
}
};
}
anchors! {
Readability {
Commented => 0.0,
Uncommented => 1.0,
Obfuscated => 4.0,
CompiledLayout => 5.0,
CompiledLogic => 6.0,
CompiledLogicLarge => 8.0,
Packed => 10.0,
}
}
anchors! {
AttackSurface {
Narrow => 0.0,
MediumMinus => 3.0,
MediumPlus => 6.0,
Wide => 8.0,
VeryWide => 10.0,
}
}
anchors! {
Locality {
Function => 0.0,
Module => 3.0,
SameCodebase => 5.0,
SameMachine => 7.0,
CrossMachine => 10.0,
}
}
anchors! {
ExpertLevel {
None => 0.0,
Introductory => 3.0,
Implementation => 6.0,
Deep => 10.0,
}
}