use std::fmt;
mod sealed {
pub trait Sealed {}
}
pub trait Redact: sealed::Sealed {
fn redacted(&self) -> String;
}
pub struct RedactedDisplay<T: fmt::Display> {
value: T,
}
impl<T: fmt::Display> RedactedDisplay<T> {
#[must_use]
pub fn new(value: T) -> Self {
Self { value }
}
#[must_use]
pub fn inner(&self) -> &T {
&self.value
}
}
impl<T: fmt::Display> sealed::Sealed for RedactedDisplay<T> {}
impl<T: fmt::Display> Redact for RedactedDisplay<T> {
fn redacted(&self) -> String {
"[REDACTED]".to_string()
}
}
impl<T: fmt::Display> fmt::Display for RedactedDisplay<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[REDACTED]")
}
}
impl<T: fmt::Display + fmt::Debug> fmt::Debug for RedactedDisplay<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "RedactedDisplay(REDACTED)")
}
}