#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct PatternPriority {
pub specificity_score: u32,
pub format_family: FormatFamily,
pub unix_timestamp_penalty: bool,
}
impl PatternPriority {
pub fn new(specificity_score: u32, format_family: FormatFamily) -> Self {
let unix_timestamp_penalty = matches!(format_family, FormatFamily::Unix);
Self {
specificity_score,
format_family,
unix_timestamp_penalty,
}
}
pub fn effective_score(&self) -> i32 {
let base_score = -i32::try_from(self.specificity_score).unwrap_or(0);
let family_modifier = match self.format_family {
FormatFamily::Structured => 0, FormatFamily::Application => 100,
FormatFamily::Regional => 200,
FormatFamily::Database => 300,
FormatFamily::Legacy => 400,
FormatFamily::Unix => 1000, };
let penalty = if self.unix_timestamp_penalty { 500 } else { 0 };
base_score + family_modifier + penalty
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum FormatFamily {
Structured, Application, Regional, Database, Legacy, Unix, }