use core::marker::PhantomData;
#[derive(Debug)]
pub struct ReturnType<T>(PhantomData<fn() -> T>);
impl<T> Clone for ReturnType<T> {
#[inline]
fn clone(&self) -> Self {
Self(Default::default())
}
}
impl<T> Copy for ReturnType<T> {}
impl<T> Default for ReturnType<T> {
#[inline]
fn default() -> Self {
Self(Default::default())
}
}
#[derive(Debug, Copy, Clone)]
pub struct Set<T>(pub T);
impl<T> Set<T> {
#[inline]
pub fn value(self) -> T {
self.0
}
}
#[derive(Debug)]
pub struct Unset<T>(PhantomData<fn() -> T>);
impl<T> Clone for Unset<T> {
#[inline]
fn clone(&self) -> Self {
Self(Default::default())
}
}
impl<T> Copy for Unset<T> {}
impl<T> Default for Unset<T> {
#[inline]
fn default() -> Self {
Self(Default::default())
}
}
pub trait Unwrap {
type Output;
fn unwrap_or_else<F>(self, f: F) -> Self::Output
where
F: FnOnce() -> Self::Output;
}
impl<T> Unwrap for Unset<T> {
type Output = T;
#[inline]
fn unwrap_or_else<F>(self, f: F) -> Self::Output
where
F: FnOnce() -> Self::Output,
{
f()
}
}
impl<T> Unwrap for Set<T> {
type Output = T;
#[inline]
fn unwrap_or_else<F>(self, _: F) -> Self::Output
where
F: FnOnce() -> Self::Output,
{
self.value()
}
}