use core::{fmt, ops};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub(crate) struct OptionDisplay<T>(Option<T>);
impl<T> OptionDisplay<T> {
pub(crate) fn as_option(&self) -> &Option<T> {
&self.0
}
}
impl<T> ops::Deref for OptionDisplay<T> {
type Target = Option<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> fmt::Display for OptionDisplay<T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
Some(t) => t.fmt(f),
None => Ok(()),
}
}
}
impl<T> From<Option<T>> for OptionDisplay<T> {
fn from(value: Option<T>) -> Self {
Self(value)
}
}
impl<T> From<OptionDisplay<T>> for Option<T> {
fn from(value: OptionDisplay<T>) -> Self {
value.0
}
}