#[derive(Clone, Copy)]
pub(crate) enum ContentCapture {
Redact,
Capture,
}
pub(crate) enum ContentBuffer {
Redacted,
Recording(String),
}
impl ContentCapture {
pub(crate) fn from_enabled(enabled: bool) -> Self {
if enabled { Self::Capture } else { Self::Redact }
}
pub(crate) fn buffer(self) -> ContentBuffer {
match self {
Self::Redact => ContentBuffer::Redacted,
Self::Capture => ContentBuffer::Recording(String::new()),
}
}
pub(crate) fn content(self, content: &str) -> Option<&str> {
match self {
Self::Redact => None,
Self::Capture => Some(content),
}
}
}
impl ContentBuffer {
pub(crate) fn push(&mut self, chunk: &str) {
if let Self::Recording(text) = self {
text.push_str(chunk);
}
}
pub(crate) fn set(&mut self, content: &str) {
if let Self::Recording(text) = self {
content.clone_into(text);
}
}
pub(crate) fn get(&self) -> Option<&str> {
match self {
Self::Recording(text) if !text.is_empty() => Some(text),
_ => None,
}
}
}