use std::fmt::{self, Display, Formatter};
use koek_redact::Redact;
pub struct DataClass {
pub name: &'static str,
pub display_behavior: DisplayBehavior,
}
impl DataClass {
pub fn classify<TValue>(&'static self, value: TValue) -> Classified<TValue> {
Classified {
class: self,
value
}
}
}
pub enum DisplayBehavior {
Clear,
DefaultRedact,
}
pub struct Classified<TValue> {
pub class: &'static DataClass,
pub value: TValue,
}
impl<TValue: Display> Display for Classified<TValue> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self.class.display_behavior {
DisplayBehavior::DefaultRedact => f.write_str(self.value.redacted().as_str()),
DisplayBehavior::Clear => self.value.fmt(f),
}
}
}