use std::borrow::Cow;
use super::{
LogSafeText,
log_escape::escape_log_control_characters,
};
#[must_use = "use the redacted value instead of the original value"]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RedactedText<'a>(
Cow<'a, str>,
);
impl<'a> RedactedText<'a> {
#[inline(always)]
pub(crate) const fn new(value: Cow<'a, str>) -> Self {
Self(value)
}
#[must_use = "use the redacted value instead of the original value"]
#[inline(always)]
pub fn as_str(&self) -> &str {
self.0.as_ref()
}
#[must_use = "use the redacted value instead of the original value"]
#[inline(always)]
pub fn into_owned(self) -> String {
self.0.into_owned()
}
#[inline]
pub fn escape_for_log(self) -> LogSafeText<'a> {
LogSafeText::from_escaped(escape_log_control_characters(self.0))
}
#[cfg(feature = "http")]
#[must_use = "use the redacted value instead of the original value"]
#[inline(always)]
pub(crate) fn into_inner(self) -> Cow<'a, str> {
self.0
}
}