#![deny(missing_docs)]
pub mod redactors;
#[cfg(any(feature = "serde", doc))]
pub mod serde;
#[cfg(any(feature = "zeroize", doc))]
pub mod zeroize;
use crate::redactors::Simple;
#[cfg(doc)]
use crate::redactors::*;
use std::cmp::Ordering;
use std::fmt::{Debug, Display, Formatter, Result};
use std::marker::PhantomData;
pub trait Redactor {
fn redact(f: &mut Formatter<'_>) -> Result;
}
pub struct Redacted<T, R = Simple>
where
R: Redactor,
{
inner: T,
_redactor: PhantomData<R>,
}
impl<T, R> Redacted<T, R>
where
R: Redactor,
{
pub fn into_inner(self) -> T {
self.inner
}
pub fn inner(&self) -> &T {
&self.inner
}
pub fn inner_mut(&mut self) -> &mut T {
&mut self.inner
}
}
impl<T, R> Default for Redacted<T, R>
where
T: Default,
R: Redactor,
{
fn default() -> Self {
Self {
inner: Default::default(),
_redactor: PhantomData,
}
}
}
impl<T, R> From<T> for Redacted<T, R>
where
R: Redactor,
{
fn from(value: T) -> Self {
Redacted {
inner: value,
_redactor: PhantomData,
}
}
}
impl<T, R> Clone for Redacted<T, R>
where
T: Clone,
R: Redactor,
{
fn clone(&self) -> Self {
Redacted {
inner: self.inner.clone(),
_redactor: PhantomData,
}
}
}
impl<T, R> Copy for Redacted<T, R>
where
T: Copy,
R: Redactor,
{
}
impl<T, R> PartialEq for Redacted<T, R>
where
T: PartialEq,
R: Redactor,
{
fn eq(&self, other: &Self) -> bool {
self.inner.eq(&other.inner)
}
}
impl<T, R> PartialEq<T> for Redacted<T, R>
where
T: PartialEq,
R: Redactor,
{
fn eq(&self, other: &T) -> bool {
self.inner.eq(other)
}
}
impl<T, R> Eq for Redacted<T, R>
where
T: Eq,
R: Redactor,
{
}
impl<T, R> PartialOrd for Redacted<T, R>
where
T: PartialOrd,
R: Redactor,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.inner.partial_cmp(&other.inner)
}
}
impl<T, R> PartialOrd<T> for Redacted<T, R>
where
T: PartialOrd,
R: Redactor,
{
fn partial_cmp(&self, other: &T) -> Option<Ordering> {
self.inner().partial_cmp(other)
}
}
impl<T, R> Ord for Redacted<T, R>
where
T: Ord,
R: Redactor,
{
fn cmp(&self, other: &Self) -> Ordering {
self.inner.cmp(&other.inner)
}
}
impl<T, R> Display for Redacted<T, R>
where
R: Redactor,
{
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
R::redact(f)
}
}
impl<T, R> Debug for Redacted<T, R>
where
R: Redactor,
{
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
R::redact(f)
}
}