use std::cell::RefCell;
use crate::RedactableWithFormatter;
#[allow(unused_imports)]
use crate::redaction::PolicyApplicableRef;
pub enum PolicyRefCellOutput<T> {
Value(RefCell<T>),
Borrowed,
}
impl<T: RedactableWithFormatter> RedactableWithFormatter for PolicyRefCellOutput<T> {
fn fmt_redacted(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Value(value) => value.fmt_redacted(f),
Self::Borrowed => f.write_str("<borrowed>"),
}
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for PolicyRefCellOutput<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Value(value) => std::fmt::Debug::fmt(value, f),
Self::Borrowed => f.write_str("<borrowed>"),
}
}
}
pub enum PolicyFormattingOutput<T> {
Value(T),
Borrowed,
}
impl<T> PolicyFormattingOutput<T> {
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> PolicyFormattingOutput<U> {
match self {
Self::Value(value) => PolicyFormattingOutput::Value(f(value)),
Self::Borrowed => PolicyFormattingOutput::Borrowed,
}
}
}
impl<T: RedactableWithFormatter> RedactableWithFormatter for PolicyFormattingOutput<T> {
fn fmt_redacted(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Value(value) => value.fmt_redacted(f),
Self::Borrowed => f.write_str("<borrowed>"),
}
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for PolicyFormattingOutput<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Value(value) => std::fmt::Debug::fmt(value, f),
Self::Borrowed => f.write_str("<borrowed>"),
}
}
}