use core::{ops::{Deref, DerefMut}, pin::Pin};
use crate::{ops::{MaybeAnd, MaybeAndThen, MaybeFilter, MaybeOr, MaybeXor}, Copied, NotVoid, PureMaybe, StaticMaybe};
pub trait Maybe<T>
where
T: ?Sized
{
const IS_MAYBE_SOME: bool;
const IS_MAYBE_NONE: bool;
const IS_NEVER_SOME: bool = !Self::IS_MAYBE_SOME;
const IS_NEVER_NONE: bool = !Self::IS_MAYBE_NONE;
const IS_ALWAYS_SOME: bool = Self::IS_MAYBE_SOME && !Self::IS_MAYBE_NONE;
const IS_ALWAYS_NONE: bool = Self::IS_MAYBE_NONE && !Self::IS_MAYBE_SOME;
type Pure: PureMaybe<T> + ?Sized
where
T: StaticMaybe<T>,
(): StaticMaybe<T>;
type PureRef<'a>: PureMaybe<&'a T>
where
Self: 'a,
T: 'a;
type PureMut<'a>: PureMaybe<&'a mut T>
where
Self: 'a,
T: 'a;
type PurePinRef<'a>: PureMaybe<Pin<&'a T>>
where
Self: 'a,
T: 'a;
type PurePinMut<'a>: PureMaybe<Pin<&'a mut T>>
where
Self: 'a,
T: 'a;
type Mapped<U>: Maybe<U>
where
U: StaticMaybe<U>,
(): StaticMaybe<U>;
type Copied: Maybe<<T as Copied>::Output>
where
T: Copied,
(): StaticMaybe<<T as Copied>::Output>;
type AsRef<'a>: Maybe<&'a T> + 'a = Self::Mapped<&'a T>
where
Self: 'a,
T: 'a;
type AsMut<'a>: Maybe<&'a mut T> + 'a = Self::Mapped<&'a mut T>
where
Self: 'a,
T: 'a;
type AsPinRef<'a>: Maybe<Pin<&'a T>> + 'a = Self::Mapped<Pin<&'a T>>
where
Self: 'a,
T: 'a;
type AsPinMut<'a>: Maybe<Pin<&'a mut T>> + 'a = Self::Mapped<Pin<&'a mut T>>
where
Self: 'a,
T: 'a;
type AsDeref<'a>: Maybe<&'a <T as Deref>::Target> + 'a = Self::Mapped<&'a <T as Deref>::Target>
where
Self: 'a,
T: Deref + 'a;
type AsDerefMut<'a>: Maybe<&'a mut <T as Deref>::Target> + 'a = Self::Mapped<&'a mut <T as Deref>::Target>
where
Self: 'a,
T: Deref + 'a;
fn is_some(&self) -> bool;
fn is_none(&self) -> bool;
fn as_ref<'a>(&'a self) -> Self::AsRef<'a>
where
T: 'a;
fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a>
where
T: 'a;
fn as_pin_ref<'a>(self: Pin<&'a Self>) -> Self::AsPinRef<'a>
where
T: 'a;
fn as_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::AsPinMut<'a>
where
T: 'a;
fn as_slice(&self) -> &[T]
where
T: Sized;
fn as_mut_slice(&mut self) -> &mut [T]
where
T: Sized;
fn expect(self, msg: &str) -> T
where
T: Sized;
fn unwrap(self) -> T
where
T: Sized;
fn unwrap_ref(&self) -> &T;
fn unwrap_mut(&mut self) -> &mut T;
fn unwrap_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T>
where
T: 'a;
fn unwrap_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T>
where
T: 'a;
fn unwrap_or(self, default: T) -> T
where
T: Sized;
fn unwrap_ref_or<'a>(&'a self, default: &'a T) -> &'a T
where
T: 'a;
fn unwrap_mut_or<'a>(&'a mut self, default: &'a mut T) -> &'a mut T
where
T: 'a;
fn unwrap_pin_ref_or<'a>(self: Pin<&'a Self>, default: Pin<&'a T>) -> Pin<&'a T>
where
T: 'a;
fn unwrap_pin_mut_or<'a>(self: Pin<&'a mut Self>, default: Pin<&'a mut T>) -> Pin<&'a mut T>
where
T: 'a;
fn unwrap_or_else<F>(self, default: F) -> T
where
F: FnOnce() -> T,
T: Sized;
fn unwrap_ref_or_else<'a, F>(&'a self, default: F) -> &'a T
where
F: FnOnce() -> &'a T,
T: 'a;
fn unwrap_mut_or_else<'a, F>(&'a mut self, default: F) -> &'a mut T
where
F: FnOnce() -> &'a mut T,
T: 'a;
fn unwrap_pin_ref_or_else<'a, F>(self: Pin<&'a Self>, default: F) -> Pin<&'a T>
where
F: FnOnce() -> Pin<&'a T>,
T: 'a;
fn unwrap_pin_mut_or_else<'a, F>(self: Pin<&'a mut Self>, default: F) -> Pin<&'a mut T>
where
F: FnOnce() -> Pin<&'a mut T>,
T: 'a;
fn unwrap_or_default(self) -> T
where
T: Sized + Default;
fn map<U, F>(self, map: F) -> Self::Mapped<U>
where
F: FnOnce(T) -> U,
T: Sized,
U: StaticMaybe<U>,
(): StaticMaybe<U>;
fn map_or<U, F>(self, default: U, map: F) -> U
where
F: FnOnce(T) -> U,
T: Sized;
fn map_or_else<U, D, F>(self, default: D, map: F) -> U
where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
T: Sized;
fn ok_or<E>(self, error: E) -> Result<T, E>
where
T: Sized;
fn ok_or_else<E, F>(self, error: F) -> Result<T, E>
where
F: FnOnce() -> E,
T: Sized;
fn as_deref<'a>(&'a self) -> Self::AsDeref<'a>
where
T: Deref + 'a;
fn as_deref_mut<'a>(&'a mut self) -> Self::AsDerefMut<'a>
where
T: DerefMut + 'a;
fn and<Rhs>(self, other: Rhs) -> <Self::Pure as MaybeAnd<T, Rhs::Pure>>::Output
where
Rhs: Maybe<T>,
Self: Sized,
Rhs::Pure: Sized,
Self::Pure: MaybeAnd<T, Rhs::Pure> + Sized,
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
<Self::Pure as MaybeAnd<T, Rhs::Pure>>::Output: Sized
{
MaybeAnd::and(self.pure(), other.pure())
}
#[doc(alias = "flatmap")]
fn and_then<U, F>(self, and_then: F) -> <Self::Pure as MaybeAndThen<T, U, <<F as FnOnce<(T,)>>::Output as Maybe<U>>::Pure>>::Output
where
F: FnOnce<(T,), Output: Maybe<U>>,
Self: Sized,
<<F as FnOnce<(T,)>>::Output as Maybe<U>>::Pure: Sized,
Self::Pure: MaybeAndThen<T, U, <<F as FnOnce<(T,)>>::Output as Maybe<U>>::Pure> + Sized,
T: StaticMaybe<T> + Sized,
U: StaticMaybe<U> + Sized,
(): StaticMaybe<T> + StaticMaybe<U>,
<Self::Pure as MaybeAndThen<T, U, <<F as FnOnce<(T,)>>::Output as Maybe<U>>::Pure>>::Output: Sized
{
MaybeAndThen::and_then(self.pure(), |x| and_then(x).pure())
}
fn filter<F>(self, predicate: F) -> <Self::Pure as MaybeFilter<T>>::Output
where
Self: Sized,
F: Fn(&T) -> bool,
Self::Pure: MaybeFilter<T> + Sized,
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
{
MaybeFilter::filter(self.pure(), predicate)
}
fn or<Rhs>(self, other: Rhs) -> <Self::Pure as MaybeOr<T, Rhs::Pure>>::Output
where
Rhs: Maybe<T>,
Self: Sized,
Rhs::Pure: Sized,
Self::Pure: MaybeOr<T, Rhs::Pure> + Sized,
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
<Self::Pure as MaybeOr<T, Rhs::Pure>>::Output: Sized
{
MaybeOr::or(self.pure(), other.pure())
}
fn or_else<F>(self, or_else: F) -> <Self::Pure as MaybeOr<T, <<F as FnOnce<()>>::Output as Maybe<T>>::Pure>>::Output
where
F: FnOnce<(), Output: Maybe<T, Pure: Sized>>,
Self: Sized,
Self::Pure: MaybeOr<T, <<F as FnOnce<()>>::Output as Maybe<T>>::Pure> + Sized,
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
<Self::Pure as MaybeOr<T, <<F as FnOnce<()>>::Output as Maybe<T>>::Pure>>::Output: Sized
{
MaybeOr::or_else(self.pure(), || or_else().pure())
}
fn xor<Rhs>(self, other: Rhs) -> <Self::Pure as MaybeXor<T, Rhs::Pure>>::Output
where
Rhs: Maybe<T>,
Self: Sized,
Rhs::Pure: Sized,
Self::Pure: MaybeXor<T, Rhs::Pure> + Sized,
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
<Self::Pure as MaybeXor<T, Rhs::Pure>>::Output: Sized
{
MaybeXor::xor(self.pure(), other.pure())
}
fn copied(&self) -> Self::Copied
where
T: Copied<Output: Copy>,
(): StaticMaybe<<T as Copied>::Output>;
fn cloned(&self) -> Self::Copied
where
T: Copied<Output: Clone>,
T: Sized,
(): StaticMaybe<<T as Copied>::Output>;
fn option(self) -> Option<T>
where
T: Sized;
fn option_ref(&self) -> Option<&T>;
fn option_mut(&mut self) -> Option<&mut T>;
fn option_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>;
fn option_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>;
fn pure(self) -> Self::Pure
where
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
Self::Pure: Sized;
fn pure_ref<'a>(&'a self) -> Self::PureRef<'a>
where
T: 'a;
fn pure_mut<'a>(&'a mut self) -> Self::PureMut<'a>
where
T: 'a;
fn pure_pin_ref<'a>(self: Pin<&'a Self>) -> Self::PurePinRef<'a>
where
T: 'a;
fn pure_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::PurePinMut<'a>
where
T: 'a;
}
impl<T> Maybe<T> for T
where
T: ?Sized
{
const IS_MAYBE_SOME: bool = true;
const IS_MAYBE_NONE: bool = false;
type Pure = T
where
T: StaticMaybe<T>,
(): StaticMaybe<T>;
type PureRef<'a> = <Self::AsRef<'a> as Maybe<&'a T>>::Pure
where
Self: 'a,
T: 'a;
type PureMut<'a> = <Self::AsMut<'a> as Maybe<&'a mut T>>::Pure
where
Self: 'a,
T: 'a;
type PurePinRef<'a> = <Self::AsPinRef<'a> as Maybe<Pin<&'a T>>>::Pure
where
Self: 'a,
T: 'a;
type PurePinMut<'a> = <Self::AsPinMut<'a> as Maybe<Pin<&'a mut T>>>::Pure
where
Self: 'a,
T: 'a;
type Mapped<U> = U
where
U: StaticMaybe<U>,
(): StaticMaybe<U>;
type Copied = Self::Mapped<<T as Copied>::Output>
where
T: Copied,
(): StaticMaybe<<T as Copied>::Output>;
fn is_some(&self) -> bool
{
true
}
fn is_none(&self) -> bool
{
false
}
fn as_ref<'a>(&'a self) -> Self::AsRef<'a>
where
T: 'a
{
self
}
fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a>
where
T: 'a
{
self
}
fn as_pin_ref<'a>(self: Pin<&'a Self>) -> Self::AsPinRef<'a>
where
T: 'a
{
unsafe {
self.map_unchecked(|this| this.as_ref())
}
}
fn as_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::AsPinMut<'a>
where
T: 'a
{
unsafe {
self.map_unchecked_mut(|this| this.as_mut())
}
}
fn as_slice(&self) -> &[T]
where
T: Sized
{
core::slice::from_ref(self)
}
fn as_mut_slice(&mut self) -> &mut [T]
where
T: Sized
{
core::slice::from_mut(self)
}
fn expect(self, _: &str) -> T
where
T: Sized
{
self
}
fn unwrap(self) -> T
where
T: Sized
{
self
}
fn unwrap_ref(&self) -> &T
{
self
}
fn unwrap_mut(&mut self) -> &mut T
{
self
}
fn unwrap_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T>
where
T: 'a
{
self
}
fn unwrap_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T>
where
T: 'a
{
self
}
fn unwrap_or(self, _: T) -> T
where
T: Sized
{
self
}
fn unwrap_ref_or<'a>(&'a self, _: &'a T) -> &'a T
where
T: 'a
{
self
}
fn unwrap_mut_or<'a>(&'a mut self, _: &'a mut T) -> &'a mut T
where
T: 'a
{
self
}
fn unwrap_pin_ref_or<'a>(self: Pin<&'a Self>, _: Pin<&'a T>) -> Pin<&'a T>
where
T: 'a
{
self
}
fn unwrap_pin_mut_or<'a>(self: Pin<&'a mut Self>, _: Pin<&'a mut T>) -> Pin<&'a mut T>
where
T: 'a
{
self
}
fn unwrap_or_else<F>(self, _: F) -> T
where
F: FnOnce() -> T,
T: Sized
{
self
}
fn unwrap_ref_or_else<'a, F>(&'a self, _: F) -> &'a T
where
F: FnOnce() -> &'a T,
T: 'a
{
self
}
fn unwrap_mut_or_else<'a, F>(&'a mut self, _: F) -> &'a mut T
where
F: FnOnce() -> &'a mut T,
T: 'a
{
self
}
fn unwrap_pin_ref_or_else<'a, F>(self: Pin<&'a Self>, _: F) -> Pin<&'a T>
where
F: FnOnce() -> Pin<&'a T>,
T: 'a
{
self
}
fn unwrap_pin_mut_or_else<'a, F>(self: Pin<&'a mut Self>, _: F) -> Pin<&'a mut T>
where
F: FnOnce() -> Pin<&'a mut T>,
T: 'a
{
self
}
fn unwrap_or_default(self) -> T
where
T: Sized + Default
{
self
}
fn map<U, F>(self, map: F) -> Self::Mapped<U>
where
F: FnOnce(T) -> U,
T: Sized,
U: StaticMaybe<U>,
(): StaticMaybe<U>
{
map(self)
}
fn map_or<U, F>(self, _: U, map: F) -> U
where
F: FnOnce(T) -> U,
T: Sized
{
map(self)
}
fn map_or_else<U, D, F>(self, _: D, map: F) -> U
where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
T: Sized
{
map(self)
}
fn ok_or<E>(self, _: E) -> Result<T, E>
where
T: Sized
{
Ok(self)
}
fn ok_or_else<E, F>(self, _: F) -> Result<T, E>
where
F: FnOnce() -> E,
T: Sized
{
Ok(self)
}
fn as_deref<'a>(&'a self) -> Self::AsDeref<'a>
where
T: Deref + 'a
{
self.deref()
}
fn as_deref_mut<'a>(&'a mut self) -> Self::AsDerefMut<'a>
where
T: DerefMut + 'a
{
self.deref_mut()
}
fn copied(&self) -> Self::Copied
where
T: Copied<Output: Copy>,
(): StaticMaybe<<T as Copied>::Output>
{
crate::copy_ref(self)
}
fn cloned(&self) -> Self::Copied
where
T: Copied<Output: Clone>,
T: Sized,
(): StaticMaybe<<T as Copied>::Output>
{
crate::clone_ref(self)
}
fn option(self) -> Option<T>
where
T: Sized
{
Some(self)
}
fn option_ref(&self) -> Option<&T>
{
Some(self)
}
fn option_mut(&mut self) -> Option<&mut T>
{
Some(self)
}
fn option_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>
{
Some(self)
}
fn option_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
{
Some(self)
}
fn pure(self) -> Self::Pure
where
T: StaticMaybe<T> + Sized,
(): StaticMaybe<T>,
Self::Pure: Sized
{
crate::assume_same(self)
}
fn pure_ref<'a>(&'a self) -> Self::PureRef<'a>
where
T: 'a
{
self
}
fn pure_mut<'a>(&'a mut self) -> Self::PureMut<'a>
where
T: 'a
{
self
}
fn pure_pin_ref<'a>(self: Pin<&'a Self>) -> Self::PurePinRef<'a>
where
T: 'a
{
self
}
fn pure_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::PurePinMut<'a>
where
T: 'a
{
self
}
}
impl<T> Maybe<T> for ()
where
T: NotVoid + ?Sized
{
const IS_MAYBE_SOME: bool = false;
const IS_MAYBE_NONE: bool = true;
type Pure = ();
type PureRef<'a> = <Self::AsRef<'a> as Maybe<&'a T>>::Pure
where
Self: 'a,
T: 'a;
type PureMut<'a> = <Self::AsMut<'a> as Maybe<&'a mut T>>::Pure
where
Self: 'a,
T: 'a;
type PurePinRef<'a> = <Self::AsPinRef<'a> as Maybe<Pin<&'a T>>>::Pure
where
Self: 'a,
T: 'a;
type PurePinMut<'a> = <Self::AsPinMut<'a> as Maybe<Pin<&'a mut T>>>::Pure
where
Self: 'a,
T: 'a;
type Mapped<U> = ()
where
U: StaticMaybe<U>,
(): StaticMaybe<U>;
type Copied = Self::Mapped<<T as Copied>::Output>
where
T: Copied,
(): StaticMaybe<<T as Copied>::Output>;
fn is_some(&self) -> bool
{
false
}
fn is_none(&self) -> bool
{
true
}
fn as_ref<'a>(&'a self) -> Self::AsRef<'a>
where
T: 'a
{
}
fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a>
where
T: 'a
{
}
fn as_pin_ref<'a>(self: Pin<&'a Self>) -> Self::AsPinRef<'a>
where
T: 'a
{
}
fn as_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::AsPinMut<'a>
where
T: 'a
{
}
fn as_slice(&self) -> &[T]
where
T: Sized
{
&[]
}
fn as_mut_slice(&mut self) -> &mut [T]
where
T: Sized
{
&mut []
}
fn expect(self, msg: &str) -> T
where
T: Sized
{
crate::on_unwrap_empty_msg(msg)
}
fn unwrap(self) -> T
where
T: Sized
{
crate::on_unwrap_empty()
}
fn unwrap_ref(&self) -> &T
{
crate::on_unwrap_empty()
}
fn unwrap_mut(&mut self) -> &mut T
{
crate::on_unwrap_empty()
}
fn unwrap_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T>
where
T: 'a
{
crate::on_unwrap_empty()
}
fn unwrap_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T>
where
T: 'a
{
crate::on_unwrap_empty()
}
fn unwrap_or(self, default: T) -> T
where
T: Sized
{
default
}
fn unwrap_ref_or<'a>(&'a self, default: &'a T) -> &'a T
where
T: 'a
{
default
}
fn unwrap_mut_or<'a>(&'a mut self, default: &'a mut T) -> &'a mut T
where
T: 'a
{
default
}
fn unwrap_pin_ref_or<'a>(self: Pin<&'a Self>, default: Pin<&'a T>) -> Pin<&'a T>
where
T: 'a
{
default
}
fn unwrap_pin_mut_or<'a>(self: Pin<&'a mut Self>, default: Pin<&'a mut T>) -> Pin<&'a mut T>
where
T: 'a
{
default
}
fn unwrap_or_else<F>(self, default: F) -> T
where
F: FnOnce() -> T,
T: Sized
{
default()
}
fn unwrap_ref_or_else<'a, F>(&'a self, default: F) -> &'a T
where
F: FnOnce() -> &'a T,
T: 'a
{
default()
}
fn unwrap_mut_or_else<'a, F>(&'a mut self, default: F) -> &'a mut T
where
F: FnOnce() -> &'a mut T,
T: 'a
{
default()
}
fn unwrap_pin_ref_or_else<'a, F>(self: Pin<&'a Self>, default: F) -> Pin<&'a T>
where
F: FnOnce() -> Pin<&'a T>,
T: 'a
{
default()
}
fn unwrap_pin_mut_or_else<'a, F>(self: Pin<&'a mut Self>, default: F) -> Pin<&'a mut T>
where
F: FnOnce() -> Pin<&'a mut T>,
T: 'a
{
default()
}
fn unwrap_or_default(self) -> T
where
T: Sized + Default
{
T::default()
}
fn map<U, F>(self, _: F) -> Self::Mapped<U>
where
F: FnOnce(T) -> U,
T: Sized,
U: StaticMaybe<U>,
(): StaticMaybe<U>
{
}
fn map_or<U, F>(self, default: U, _: F) -> U
where
F: FnOnce(T) -> U,
T: Sized
{
default
}
fn map_or_else<U, D, F>(self, default: D, _: F) -> U
where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
T: Sized
{
default()
}
fn ok_or<E>(self, error: E) -> Result<T, E>
where
T: Sized
{
Err(error)
}
fn ok_or_else<E, F>(self, error: F) -> Result<T, E>
where
F: FnOnce() -> E,
T: Sized
{
Err(error())
}
fn as_deref<'a>(&'a self) -> Self::AsDeref<'a>
where
T: Deref + 'a
{
}
fn as_deref_mut<'a>(&'a mut self) -> Self::AsDerefMut<'a>
where
T: DerefMut + 'a
{
}
fn copied(&self) -> Self::Copied
where
T: Copied<Output: Copy>,
(): StaticMaybe<<T as Copied>::Output>
{
}
fn cloned(&self) -> Self::Copied
where
T: Copied<Output: Clone>,
(): StaticMaybe<<T as Copied>::Output>
{
}
fn option(self) -> Option<T>
where
T: Sized
{
None
}
fn option_ref(&self) -> Option<&T>
{
None
}
fn option_mut(&mut self) -> Option<&mut T>
{
None
}
fn option_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>
{
None
}
fn option_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
{
None
}
fn pure(self) -> Self::Pure
{
}
fn pure_ref<'a>(&'a self) -> Self::PureRef<'a>
where
T: 'a
{
}
fn pure_mut<'a>(&'a mut self) -> Self::PureMut<'a>
where
T: 'a
{
}
fn pure_pin_ref<'a>(self: Pin<&'a Self>) -> Self::PurePinRef<'a>
where
T: 'a
{
}
fn pure_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::PurePinMut<'a>
where
T: 'a
{
}
}
impl<T> Maybe<T> for Option<T>
{
const IS_MAYBE_SOME: bool = true;
const IS_MAYBE_NONE: bool = true;
type Pure = Option<T>
where
T: StaticMaybe<T>,
(): StaticMaybe<T>;
type PureRef<'a> = <Self::AsRef<'a> as Maybe<&'a T>>::Pure
where
Self: 'a,
T: 'a;
type PureMut<'a> = <Self::AsMut<'a> as Maybe<&'a mut T>>::Pure
where
Self: 'a,
T: 'a;
type PurePinRef<'a> = <Self::AsPinRef<'a> as Maybe<Pin<&'a T>>>::Pure
where
Self: 'a,
T: 'a;
type PurePinMut<'a> = <Self::AsPinMut<'a> as Maybe<Pin<&'a mut T>>>::Pure
where
Self: 'a,
T: 'a;
type Mapped<U> = Option<U>
where
U: StaticMaybe<U>,
(): StaticMaybe<U>;
type Copied = Self::Mapped<<T as Copied>::Output>
where
T: Copied,
(): StaticMaybe<<T as Copied>::Output>;
fn is_some(&self) -> bool
{
self.is_some()
}
fn is_none(&self) -> bool
{
self.is_none()
}
fn as_ref<'a>(&'a self) -> Self::AsRef<'a>
where
T: 'a
{
self.as_ref()
}
fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a>
where
T: 'a
{
self.as_mut()
}
fn as_pin_ref<'a>(self: Pin<&'a Self>) -> Self::AsPinRef<'a>
where
T: 'a
{
self.as_pin_ref()
}
fn as_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::AsPinMut<'a>
where
T: 'a
{
self.as_pin_mut()
}
fn as_slice(&self) -> &[T]
where
T: Sized
{
self.as_slice()
}
fn as_mut_slice(&mut self) -> &mut [T]
where
T: Sized
{
self.as_mut_slice()
}
fn expect(self, msg: &str) -> T
where
T: Sized
{
self.expect(msg)
}
fn unwrap(self) -> T
where
T: Sized
{
self.unwrap()
}
fn unwrap_ref(&self) -> &T
{
self.as_ref().unwrap()
}
fn unwrap_mut(&mut self) -> &mut T
{
self.as_mut().unwrap()
}
fn unwrap_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T>
where
T: 'a
{
self.as_pin_ref().unwrap()
}
fn unwrap_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T>
where
T: 'a
{
self.as_pin_mut().unwrap()
}
fn unwrap_or(self, default: T) -> T
where
T: Sized
{
self.unwrap_or(default)
}
fn unwrap_ref_or<'a>(&'a self, default: &'a T) -> &'a T
where
T: 'a
{
self.as_ref().unwrap_or(default)
}
fn unwrap_mut_or<'a>(&'a mut self, default: &'a mut T) -> &'a mut T
where
T: 'a
{
self.as_mut().unwrap_or(default)
}
fn unwrap_pin_ref_or<'a>(self: Pin<&'a Self>, default: Pin<&'a T>) -> Pin<&'a T>
where
T: 'a
{
self.as_pin_ref().unwrap_or(default)
}
fn unwrap_pin_mut_or<'a>(self: Pin<&'a mut Self>, default: Pin<&'a mut T>) -> Pin<&'a mut T>
where
T: 'a
{
self.as_pin_mut().unwrap_or(default)
}
fn unwrap_or_else<F>(self, default: F) -> T
where
F: FnOnce() -> T,
T: Sized
{
self.unwrap_or_else(default)
}
fn unwrap_ref_or_else<'a, F>(&'a self, default: F) -> &'a T
where
F: FnOnce() -> &'a T,
T: 'a
{
self.as_ref().unwrap_or_else(default)
}
fn unwrap_mut_or_else<'a, F>(&'a mut self, default: F) -> &'a mut T
where
F: FnOnce() -> &'a mut T,
T: 'a
{
self.as_mut().unwrap_or_else(default)
}
fn unwrap_pin_ref_or_else<'a, F>(self: Pin<&'a Self>, default: F) -> Pin<&'a T>
where
F: FnOnce() -> Pin<&'a T>,
T: 'a
{
self.as_pin_ref().unwrap_or_else(default)
}
fn unwrap_pin_mut_or_else<'a, F>(self: Pin<&'a mut Self>, default: F) -> Pin<&'a mut T>
where
F: FnOnce() -> Pin<&'a mut T>,
T: 'a
{
self.as_pin_mut().unwrap_or_else(default)
}
fn unwrap_or_default(self) -> T
where
T: Sized + Default
{
self.unwrap_or_default()
}
fn map<U, F>(self, map: F) -> Self::Mapped<U>
where
F: FnOnce(T) -> U,
T: Sized,
U: StaticMaybe<U>,
(): StaticMaybe<U>
{
self.map(map)
}
fn map_or<U, F>(self, default: U, map: F) -> U
where
F: FnOnce(T) -> U,
T: Sized
{
self.map_or(default, map)
}
fn map_or_else<U, D, F>(self, default: D, map: F) -> U
where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
T: Sized
{
self.map_or_else(default, map)
}
fn ok_or<E>(self, error: E) -> Result<T, E>
where
T: Sized
{
self.ok_or(error)
}
fn ok_or_else<E, F>(self, error: F) -> Result<T, E>
where
F: FnOnce() -> E,
T: Sized
{
self.ok_or_else(error)
}
fn as_deref<'a>(&'a self) -> Self::AsDeref<'a>
where
T: Deref + 'a
{
self.as_deref()
}
fn as_deref_mut<'a>(&'a mut self) -> Self::AsDerefMut<'a>
where
T: DerefMut + 'a
{
self.as_deref_mut()
}
fn copied(&self) -> Self::Copied
where
T: Copied<Output: Copy>,
(): StaticMaybe<<T as Copied>::Output>
{
self.as_ref()
.map(crate::copy_ref)
}
fn cloned(&self) -> Self::Copied
where
T: Copied<Output: Clone>,
T: Sized,
(): StaticMaybe<<T as Copied>::Output>
{
self.as_ref()
.map(crate::clone_ref)
}
fn option(self) -> Option<T>
{
self
}
fn option_ref(&self) -> Option<&T>
{
self.as_ref()
}
fn option_mut(&mut self) -> Option<&mut T>
{
self.as_mut()
}
fn option_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>
{
self.as_pin_ref()
}
fn option_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
{
self.as_pin_mut()
}
fn pure(self) -> Self::Pure
where
T: StaticMaybe<T>,
(): StaticMaybe<T>
{
self
}
fn pure_ref<'a>(&'a self) -> Self::PureRef<'a>
where
T: 'a
{
self.as_ref()
}
fn pure_mut<'a>(&'a mut self) -> Self::PureMut<'a>
where
T: 'a
{
self.as_mut()
}
fn pure_pin_ref<'a>(self: Pin<&'a Self>) -> Self::PurePinRef<'a>
where
T: 'a
{
self.as_pin_ref()
}
fn pure_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::PurePinMut<'a>
where
T: 'a
{
self.as_pin_mut()
}
}
impl<T> Maybe<T> for [T; 0]
{
const IS_MAYBE_SOME: bool = false;
const IS_MAYBE_NONE: bool = true;
type Pure = <() as Maybe<T>>::Pure
where
T: StaticMaybe<T>,
(): StaticMaybe<T>;
type PureRef<'a> = <Self::AsRef<'a> as Maybe<&'a T>>::Pure
where
Self: 'a,
T: 'a;
type PureMut<'a> = <Self::AsMut<'a> as Maybe<&'a mut T>>::Pure
where
Self: 'a,
T: 'a;
type PurePinRef<'a> = <Self::AsPinRef<'a> as Maybe<Pin<&'a T>>>::Pure
where
Self: 'a,
T: 'a;
type PurePinMut<'a> = <Self::AsPinMut<'a> as Maybe<Pin<&'a mut T>>>::Pure
where
Self: 'a,
T: 'a;
type Mapped<U> = [U; 0]
where
U: StaticMaybe<U>,
(): StaticMaybe<U>;
type Copied = Self::Mapped<<T as Copied>::Output>
where
T: Copied,
(): StaticMaybe<<T as Copied>::Output>;
fn is_some(&self) -> bool
{
false
}
fn is_none(&self) -> bool
{
true
}
fn as_ref<'a>(&'a self) -> Self::AsRef<'a>
where
T: 'a
{
[]
}
fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a>
where
T: 'a
{
[]
}
fn as_pin_ref<'a>(self: Pin<&'a Self>) -> Self::AsPinRef<'a>
where
T: 'a
{
[]
}
fn as_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::AsPinMut<'a>
where
T: 'a
{
[]
}
fn as_slice(&self) -> &[T]
where
T: Sized
{
&[]
}
fn as_mut_slice(&mut self) -> &mut [T]
where
T: Sized
{
&mut []
}
fn expect(self, msg: &str) -> T
where
T: Sized
{
crate::on_unwrap_empty_msg(msg)
}
fn unwrap(self) -> T
where
T: Sized
{
crate::on_unwrap_empty()
}
fn unwrap_ref(&self) -> &T
{
crate::on_unwrap_empty()
}
fn unwrap_mut(&mut self) -> &mut T
{
crate::on_unwrap_empty()
}
fn unwrap_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T>
where
T: 'a
{
crate::on_unwrap_empty()
}
fn unwrap_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T>
where
T: 'a
{
crate::on_unwrap_empty()
}
fn unwrap_or(self, default: T) -> T
where
T: Sized
{
default
}
fn unwrap_ref_or<'a>(&'a self, default: &'a T) -> &'a T
where
T: 'a
{
default
}
fn unwrap_mut_or<'a>(&'a mut self, default: &'a mut T) -> &'a mut T
where
T: 'a
{
default
}
fn unwrap_pin_ref_or<'a>(self: Pin<&'a Self>, default: Pin<&'a T>) -> Pin<&'a T>
where
T: 'a
{
default
}
fn unwrap_pin_mut_or<'a>(self: Pin<&'a mut Self>, default: Pin<&'a mut T>) -> Pin<&'a mut T>
where
T: 'a
{
default
}
fn unwrap_or_else<F>(self, default: F) -> T
where
F: FnOnce() -> T,
T: Sized
{
default()
}
fn unwrap_ref_or_else<'a, F>(&'a self, default: F) -> &'a T
where
F: FnOnce() -> &'a T,
T: 'a
{
default()
}
fn unwrap_mut_or_else<'a, F>(&'a mut self, default: F) -> &'a mut T
where
F: FnOnce() -> &'a mut T,
T: 'a
{
default()
}
fn unwrap_pin_ref_or_else<'a, F>(self: Pin<&'a Self>, default: F) -> Pin<&'a T>
where
F: FnOnce() -> Pin<&'a T>,
T: 'a
{
default()
}
fn unwrap_pin_mut_or_else<'a, F>(self: Pin<&'a mut Self>, default: F) -> Pin<&'a mut T>
where
F: FnOnce() -> Pin<&'a mut T>,
T: 'a
{
default()
}
fn unwrap_or_default(self) -> T
where
T: Sized + Default
{
T::default()
}
fn map<U, F>(self, _: F) -> Self::Mapped<U>
where
F: FnOnce(T) -> U,
T: Sized,
U: StaticMaybe<U>,
(): StaticMaybe<U>
{
[]
}
fn map_or<U, F>(self, default: U, _: F) -> U
where
F: FnOnce(T) -> U,
T: Sized
{
default
}
fn map_or_else<U, D, F>(self, default: D, _: F) -> U
where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
T: Sized
{
default()
}
fn ok_or<E>(self, error: E) -> Result<T, E>
where
T: Sized
{
Err(error)
}
fn ok_or_else<E, F>(self, error: F) -> Result<T, E>
where
F: FnOnce() -> E,
T: Sized
{
Err(error())
}
fn as_deref<'a>(&'a self) -> Self::AsDeref<'a>
where
T: Deref + 'a
{
[]
}
fn as_deref_mut<'a>(&'a mut self) -> Self::AsDerefMut<'a>
where
T: DerefMut + 'a
{
[]
}
fn copied(&self) -> Self::Copied
where
T: Copied<Output: Copy>,
(): StaticMaybe<<T as Copied>::Output>
{
[]
}
fn cloned(&self) -> Self::Copied
where
T: Copied<Output: Clone>,
(): StaticMaybe<<T as Copied>::Output>
{
[]
}
fn option(self) -> Option<T>
where
T: Sized
{
None
}
fn option_ref(&self) -> Option<&T>
{
None
}
fn option_mut(&mut self) -> Option<&mut T>
{
None
}
fn option_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>
{
None
}
fn option_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
{
None
}
fn pure(self) -> Self::Pure
where
T: StaticMaybe<T>,
(): StaticMaybe<T>,
Self::Pure: Sized
{
crate::assume_same(())
}
fn pure_ref<'a>(&'a self) -> Self::PureRef<'a>
where
T: 'a
{
}
fn pure_mut<'a>(&'a mut self) -> Self::PureMut<'a>
where
T: 'a
{
}
fn pure_pin_ref<'a>(self: Pin<&'a Self>) -> Self::PurePinRef<'a>
where
T: 'a
{
}
fn pure_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::PurePinMut<'a>
where
T: 'a
{
}
}
impl<T> Maybe<T> for [T; 1]
{
const IS_MAYBE_SOME: bool = true;
const IS_MAYBE_NONE: bool = false;
type Pure = T
where
T: StaticMaybe<T>,
(): StaticMaybe<T>;
type PureRef<'a> = <Self::AsRef<'a> as Maybe<&'a T>>::Pure
where
Self: 'a,
T: 'a;
type PureMut<'a> = <Self::AsMut<'a> as Maybe<&'a mut T>>::Pure
where
Self: 'a,
T: 'a;
type PurePinRef<'a> = <Self::AsPinRef<'a> as Maybe<Pin<&'a T>>>::Pure
where
Self: 'a,
T: 'a;
type PurePinMut<'a> = <Self::AsPinMut<'a> as Maybe<Pin<&'a mut T>>>::Pure
where
Self: 'a,
T: 'a;
type Mapped<U> = [U; 1]
where
U: StaticMaybe<U>,
(): StaticMaybe<U>;
type Copied = Self::Mapped<<T as Copied>::Output>
where
T: Copied,
(): StaticMaybe<<T as Copied>::Output>;
fn is_some(&self) -> bool
{
true
}
fn is_none(&self) -> bool
{
false
}
fn as_ref<'a>(&'a self) -> Self::AsRef<'a>
where
T: 'a
{
[&self[0]]
}
fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a>
where
T: 'a
{
[&mut self[0]]
}
fn as_pin_ref<'a>(self: Pin<&'a Self>) -> Self::AsPinRef<'a>
where
T: 'a
{
[
unsafe {
self.map_unchecked(|this| &this[0])
}
]
}
fn as_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::AsPinMut<'a>
where
T: 'a
{
[
unsafe {
self.map_unchecked_mut(|this| &mut this[0])
}
]
}
fn as_slice(&self) -> &[T]
where
T: Sized
{
self
}
fn as_mut_slice(&mut self) -> &mut [T]
where
T: Sized
{
self
}
fn expect(self, _: &str) -> T
where
T: Sized
{
self.unwrap()
}
fn unwrap(self) -> T
where
T: Sized
{
let [value] = self;
value
}
fn unwrap_ref(&self) -> &T
{
&self[0]
}
fn unwrap_mut(&mut self) -> &mut T
{
&mut self[0]
}
fn unwrap_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T>
where
T: 'a
{
unsafe {
self.map_unchecked(|this| this.unwrap_ref())
}
}
fn unwrap_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T>
where
T: 'a
{
unsafe {
self.map_unchecked_mut(|this| this.unwrap_mut())
}
}
fn unwrap_or(self, _: T) -> T
where
T: Sized
{
self.unwrap()
}
fn unwrap_ref_or<'a>(&'a self, _: &'a T) -> &'a T
where
T: 'a
{
self.unwrap_ref()
}
fn unwrap_mut_or<'a>(&'a mut self, _: &'a mut T) -> &'a mut T
where
T: 'a
{
self.unwrap_mut()
}
fn unwrap_pin_ref_or<'a>(self: Pin<&'a Self>, _: Pin<&'a T>) -> Pin<&'a T>
where
T: 'a
{
self.unwrap_pin_ref()
}
fn unwrap_pin_mut_or<'a>(self: Pin<&'a mut Self>, _: Pin<&'a mut T>) -> Pin<&'a mut T>
where
T: 'a
{
self.unwrap_pin_mut()
}
fn unwrap_or_else<F>(self, _: F) -> T
where
F: FnOnce() -> T,
T: Sized
{
self.unwrap()
}
fn unwrap_ref_or_else<'a, F>(&'a self, _: F) -> &'a T
where
F: FnOnce() -> &'a T,
T: 'a
{
self.unwrap_ref()
}
fn unwrap_mut_or_else<'a, F>(&'a mut self, _: F) -> &'a mut T
where
F: FnOnce() -> &'a mut T,
T: 'a
{
self.unwrap_mut()
}
fn unwrap_pin_ref_or_else<'a, F>(self: Pin<&'a Self>, _: F) -> Pin<&'a T>
where
F: FnOnce() -> Pin<&'a T>,
T: 'a
{
self.unwrap_pin_ref()
}
fn unwrap_pin_mut_or_else<'a, F>(self: Pin<&'a mut Self>, _: F) -> Pin<&'a mut T>
where
F: FnOnce() -> Pin<&'a mut T>,
T: 'a
{
self.unwrap_pin_mut()
}
fn unwrap_or_default(self) -> T
where
T: Sized + Default
{
self.unwrap()
}
fn map<U, F>(self, map: F) -> Self::Mapped<U>
where
F: FnOnce(T) -> U,
T: Sized,
U: StaticMaybe<U>,
(): StaticMaybe<U>
{
[map(self.unwrap())]
}
fn map_or<U, F>(self, _: U, map: F) -> U
where
F: FnOnce(T) -> U,
T: Sized
{
map(self.unwrap())
}
fn map_or_else<U, D, F>(self, _: D, map: F) -> U
where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
T: Sized
{
map(self.unwrap())
}
fn ok_or<E>(self, _: E) -> Result<T, E>
where
T: Sized
{
Ok(self.unwrap())
}
fn ok_or_else<E, F>(self, _: F) -> Result<T, E>
where
F: FnOnce() -> E,
T: Sized
{
Ok(self.unwrap())
}
fn as_deref<'a>(&'a self) -> Self::AsDeref<'a>
where
T: Deref + 'a
{
[self[0].deref()]
}
fn as_deref_mut<'a>(&'a mut self) -> Self::AsDerefMut<'a>
where
T: DerefMut + 'a
{
[self[0].deref_mut()]
}
fn option(self) -> Option<T>
where
T: Sized
{
let value = unsafe {
core::ptr::read(&self[0])
};
core::mem::forget(self);
Some(value)
}
fn option_ref(&self) -> Option<&T>
{
Some(&self[0])
}
fn option_mut(&mut self) -> Option<&mut T>
{
Some(&mut self[0])
}
fn option_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>
{
Some(unsafe {
self.map_unchecked(|this| &this[0])
})
}
fn option_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
{
Some(unsafe {
self.map_unchecked_mut(|this| &mut this[0])
})
}
fn copied(&self) -> Self::Copied
where
T: Copied<Output: Copy>,
(): StaticMaybe<<T as Copied>::Output>
{
[crate::copy_ref(&self[0])]
}
fn cloned(&self) -> Self::Copied
where
T: Copied<Output: Clone>,
(): StaticMaybe<<T as Copied>::Output>
{
[crate::clone_ref(&self[0])]
}
fn pure(self) -> Self::Pure
where
T: StaticMaybe<T>,
(): StaticMaybe<T>
{
self.unwrap()
}
fn pure_ref<'a>(&'a self) -> Self::PureRef<'a>
where
T: 'a
{
&self[0]
}
fn pure_mut<'a>(&'a mut self) -> Self::PureMut<'a>
where
T: 'a
{
&mut self[0]
}
fn pure_pin_ref<'a>(self: Pin<&'a Self>) -> Self::PurePinRef<'a>
where
T: 'a
{
unsafe {
self.map_unchecked(|this| &this[0])
}
}
fn pure_pin_mut<'a>(self: Pin<&'a mut Self>) -> Self::PurePinMut<'a>
where
T: 'a
{
unsafe {
self.map_unchecked_mut(|this| &mut this[0])
}
}
}
#[cfg(test)]
mod test
{
use core::pin::Pin;
use crate::*;
use static_assertions::*;
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::Pure, Option<i32>);
assert_type_eq_all!(<i32 as Maybe<i32>>::Pure, i32);
assert_type_eq_all!(<() as Maybe<i32>>::Pure, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::Pure, i32);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::Pure, ());
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::PureRef<'static>, Option<&i32>);
assert_type_eq_all!(<i32 as Maybe<i32>>::PureRef<'static>, &i32);
assert_type_eq_all!(<() as Maybe<i32>>::PureRef<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::PureRef<'static>, &i32);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::PureRef<'static>, ());
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::PureMut<'static>, Option<&mut i32>);
assert_type_eq_all!(<i32 as Maybe<i32>>::PureMut<'static>, &mut i32);
assert_type_eq_all!(<() as Maybe<i32>>::PureMut<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::PureMut<'static>, &mut i32);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::PureMut<'static>, ());
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::PurePinRef<'static>, Option<Pin<&i32>>);
assert_type_eq_all!(<i32 as Maybe<i32>>::PurePinRef<'static>, Pin<&i32>);
assert_type_eq_all!(<() as Maybe<i32>>::PurePinRef<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::PurePinRef<'static>, Pin<&i32>);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::PurePinRef<'static>, ());
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::PurePinMut<'static>, Option<Pin<&mut i32>>);
assert_type_eq_all!(<i32 as Maybe<i32>>::PurePinMut<'static>, Pin<&mut i32>);
assert_type_eq_all!(<() as Maybe<i32>>::PurePinMut<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::PurePinMut<'static>, Pin<&mut i32>);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::PurePinMut<'static>, ());
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::Mapped<u64>, Option<u64>);
assert_type_eq_all!(<i32 as Maybe<i32>>::Mapped<u64>, u64);
assert_type_eq_all!(<() as Maybe<i32>>::Mapped<u64>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::Mapped<u64>, [u64; 1]);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::Mapped<u64>, [u64; 0]);
assert_type_eq_all!(<Option<&i32> as Maybe<&i32>>::Copied, Option<i32>);
assert_type_eq_all!(<&i32 as Maybe<&i32>>::Copied, i32);
assert_type_eq_all!(<() as Maybe<&i32>>::Copied, ());
assert_type_eq_all!(<[&i32; 1] as Maybe<&i32>>::Copied, [i32; 1]);
assert_type_eq_all!(<[&i32; 0] as Maybe<&i32>>::Copied, [i32; 0]);
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::AsRef<'static>, Option<&i32>);
assert_type_eq_all!(<i32 as Maybe<i32>>::AsRef<'static>, &i32);
assert_type_eq_all!(<() as Maybe<i32>>::AsRef<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::AsRef<'static>, [&i32; 1]);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::AsRef<'static>, [&i32; 0]);
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::AsMut<'static>, Option<&mut i32>);
assert_type_eq_all!(<i32 as Maybe<i32>>::AsMut<'static>, &mut i32);
assert_type_eq_all!(<() as Maybe<i32>>::AsMut<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::AsMut<'static>, [&mut i32; 1]);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::AsMut<'static>, [&mut i32; 0]);
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::AsPinRef<'static>, Option<Pin<&i32>>);
assert_type_eq_all!(<i32 as Maybe<i32>>::AsPinRef<'static>, Pin<&i32>);
assert_type_eq_all!(<() as Maybe<i32>>::AsPinRef<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::AsPinRef<'static>, [Pin<&i32>; 1]);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::AsPinRef<'static>, [Pin<&i32>; 0]);
assert_type_eq_all!(<Option<i32> as Maybe<i32>>::AsPinMut<'static>, Option<Pin<&mut i32>>);
assert_type_eq_all!(<i32 as Maybe<i32>>::AsPinMut<'static>, Pin<&mut i32>);
assert_type_eq_all!(<() as Maybe<i32>>::AsPinMut<'static>, ());
assert_type_eq_all!(<[i32; 1] as Maybe<i32>>::AsPinMut<'static>, [Pin<&mut i32>; 1]);
assert_type_eq_all!(<[i32; 0] as Maybe<i32>>::AsPinMut<'static>, [Pin<&mut i32>; 0]);
assert_type_eq_all!(<Option<Box<i32>> as Maybe<Box<i32>>>::AsDeref<'static>, Option<&i32>);
assert_type_eq_all!(<Box<i32> as Maybe<Box<i32>>>::AsDeref<'static>, &i32);
assert_type_eq_all!(<() as Maybe<Box<i32>>>::AsDeref<'static>, ());
assert_type_eq_all!(<[Box<i32>; 1] as Maybe<Box<i32>>>::AsDeref<'static>, [&i32; 1]);
assert_type_eq_all!(<[Box<i32>; 0] as Maybe<Box<i32>>>::AsDeref<'static>, [&i32; 0]);
}