use std::{env, fmt::Debug};
pub trait Obfuscate {
fn to_obfuscate(&mut self) -> &mut String;
}
impl Obfuscate for String {
fn to_obfuscate(&mut self) -> &mut Self {
self.replace_range(
(self.len() / 2)..self.len(),
(0..(self.len() / 2))
.map(|_| "#")
.collect::<String>()
.as_str(),
);
self
}
}
pub const LOG_DATA: &str = "LOG_DATA";
pub const MESSAGE_SEE_VALUE_IN_DEBUG_MODE: &str = "[set LOG_DATA=1 to see 🔎]";
pub trait DisplayOnlyForDebugging {
fn display_only_for_debugging(&self) -> String;
}
impl<T> DisplayOnlyForDebugging for T
where
T: Debug,
{
fn display_only_for_debugging(&self) -> String {
match env::var(LOG_DATA) {
Ok(env) => match env.as_str() {
"true" | "1" => format!("{:?}", self),
_ => MESSAGE_SEE_VALUE_IN_DEBUG_MODE.to_string(),
},
_ => MESSAGE_SEE_VALUE_IN_DEBUG_MODE.to_string(),
}
}
}