mod domain;
#[cfg(feature = "http")]
mod http;
#[cfg(feature = "json")]
mod internal;
#[cfg(feature = "json")]
mod json;
mod process;
#[cfg(feature = "uri")]
mod uri;
use std::mem::replace;
use std::sync::Arc;
use std::sync::PoisonError;
use crate::DiagnosticRedactionBatch;
use crate::RedactedTextComposer;
use crate::RedactionPolicy;
use crate::runtime::BatchSession;
use crate::runtime::InspectionSession;
use crate::runtime::TextSession;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Redactor {
policy: Arc<RedactionPolicy>,
}
impl Redactor {
#[must_use]
#[inline(always)]
pub fn new(policy: RedactionPolicy) -> Self {
Self {
policy: Arc::new(policy),
}
}
#[must_use]
#[inline(always)]
pub fn standard() -> Self {
Self::new(RedactionPolicy::standard())
}
#[must_use]
#[inline(always)]
pub fn strict() -> Self {
Self::new(RedactionPolicy::strict())
}
#[must_use]
pub fn application_default() -> Self {
match crate::facade::default_redactor::slot().read() {
Ok(redactor) => redactor.clone(),
Err(error) => PoisonError::into_inner(error).clone(),
}
}
#[must_use]
#[inline(always)]
pub fn text_composer(&self) -> RedactedTextComposer {
RedactedTextComposer::from_session(self.text_runtime())
}
#[must_use]
#[inline(always)]
pub fn diagnostic_batch(&self) -> DiagnosticRedactionBatch {
DiagnosticRedactionBatch::from_session(self.batch_runtime())
}
#[must_use]
#[inline(always)]
pub(crate) fn text_runtime(&self) -> TextSession {
TextSession::new(Arc::clone(&self.policy))
}
#[must_use]
#[inline(always)]
pub(crate) fn batch_runtime(&self) -> BatchSession {
BatchSession::new(Arc::clone(&self.policy))
}
#[must_use]
#[inline(always)]
pub(crate) fn inspection_runtime(&self) -> InspectionSession {
InspectionSession::new(Arc::clone(&self.policy))
}
#[must_use]
#[inline(always)]
pub fn policy(&self) -> &RedactionPolicy {
self.policy.as_ref()
}
#[must_use]
pub fn replace_application_default(redactor: Self) -> Self {
let mut current = match crate::facade::default_redactor::slot().write() {
Ok(guard) => guard,
Err(error) => PoisonError::into_inner(error),
};
replace(&mut *current, redactor)
}
}
impl Default for Redactor {
#[inline(always)]
fn default() -> Self {
Self::standard()
}
}