use std::marker::PhantomData;
use std::panic::AssertUnwindSafe;
use std::panic::catch_unwind;
use std::panic::resume_unwind;
pub use self::config::After;
pub use self::config::Fully;
use crate::misc::redacted::serde_impls::TRACING_SERIALIZE;
pub mod config;
mod serde_impls;
mod std_impls;
pub struct Redacted<T, Config = Fully> {
pub sensitiv: T,
config: PhantomData<Config>,
}
impl<T, Config> Redacted<T, Config>
where
Config: config::RedactionConfig,
{
pub const fn new(value: T) -> Self {
Self {
sensitiv: value,
config: PhantomData,
}
}
}
impl Redacted<()> {
pub fn with_tracing_serialize<R>(f: impl FnOnce() -> R) -> R {
TRACING_SERIALIZE.set(true);
let result = catch_unwind(AssertUnwindSafe(f));
TRACING_SERIALIZE.set(false);
match result {
Ok(x) => x,
Err(x) => resume_unwind(x),
}
}
}