use std::borrow::Cow;
use crate::{
MaskingPolicy,
Sensitivity,
};
pub trait RedactValueMut {
fn redact_value_in_place(
&mut self,
level: Sensitivity,
masking: &MaskingPolicy,
);
}
impl RedactValueMut for String {
#[inline]
fn redact_value_in_place(
&mut self,
level: Sensitivity,
masking: &MaskingPolicy,
) {
if let Cow::Owned(redacted) = masking.mask(level, self) {
*self = redacted;
}
}
}
impl RedactValueMut for Cow<'_, str> {
#[inline]
fn redact_value_in_place(
&mut self,
level: Sensitivity,
masking: &MaskingPolicy,
) {
if let Cow::Owned(redacted) = masking.mask(level, self.as_ref()) {
*self = Cow::Owned(redacted);
}
}
}
impl<T: RedactValueMut> RedactValueMut for Option<T> {
#[inline]
fn redact_value_in_place(
&mut self,
level: Sensitivity,
masking: &MaskingPolicy,
) {
if let Some(value) = self {
value.redact_value_in_place(level, masking);
}
}
}