use std::fmt::{
self,
Debug,
Display,
Formatter,
};
use crate::LogSafeText;
use super::{
UriComponent,
UriRedactionReason,
UriRedactionStatus,
};
#[must_use]
#[derive(Clone, PartialEq, Eq)]
pub struct UriRedaction {
pub(crate) text: LogSafeText<'static>,
pub(crate) status: UriRedactionStatus,
pub(crate) reasons: Vec<UriRedactionReason>,
pub(crate) components: Vec<UriComponent>,
pub(crate) truncated: bool,
}
impl UriRedaction {
#[must_use = "use the safe text when logging the URI"]
#[inline]
pub fn log_safe_text(&self) -> &LogSafeText<'static> {
&self.text
}
#[must_use = "consume the result to obtain safe text"]
#[inline]
pub fn into_log_safe_text(self) -> LogSafeText<'static> {
self.text
}
#[must_use = "inspect the URI processing status"]
#[inline]
pub const fn status(&self) -> UriRedactionStatus {
self.status
}
#[must_use = "inspect the URI processing reasons"]
#[inline]
pub fn reasons(&self) -> &[UriRedactionReason] {
&self.reasons
}
#[must_use]
#[inline]
pub const fn has_sensitive_components(&self) -> bool {
!self.components.is_empty()
}
#[must_use]
#[inline]
pub fn has_sensitive_component(&self, component: UriComponent) -> bool {
self.components.contains(&component)
}
#[must_use]
#[inline]
pub fn has_reason(&self, reason: UriRedactionReason) -> bool {
self.reasons.contains(&reason)
}
#[must_use]
#[inline]
pub const fn is_truncated(&self) -> bool {
self.truncated
}
}
impl Debug for UriRedaction {
#[inline]
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("UriRedaction")
.field("text", &self.text.as_str())
.field("status", &self.status)
.field("reasons", &self.reasons)
.field("components", &self.components)
.field("truncated", &self.truncated)
.finish()
}
}
impl Display for UriRedaction {
#[inline]
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str(self.text.as_str())
}
}