#[cfg(feature = "either")]
pub use either::Either;
pub use maybe_owned::MaybeOwned;
mod callbacks;
pub(crate) use crate::types::callbacks::Callbacks;
mod storage;
pub(crate) use crate::types::storage::Storage;
pub trait SumType2 {
type Type1;
type Type2;
fn from_type1(val: Self::Type1) -> Self;
fn from_type2(val: Self::Type2) -> Self;
fn is_type1(&self) -> bool;
fn is_type2(&self) -> bool;
fn into_type1(self) -> Option<Self::Type1>;
fn into_type2(self) -> Option<Self::Type2>;
}
impl<T> SumType2 for Option<T> {
type Type1 = T;
type Type2 = ();
#[inline]
fn from_type1(val: Self::Type1) -> Self {
Some(val)
}
#[inline]
fn from_type2(_: Self::Type2) -> Self {
None
}
#[inline]
fn is_type1(&self) -> bool {
self.is_some()
}
#[inline]
fn is_type2(&self) -> bool {
self.is_none()
}
#[inline]
fn into_type1(self) -> Option<Self::Type1> {
self
}
#[inline]
fn into_type2(self) -> Option<Self::Type2> {
self.ok_or(()).err()
}
}
impl<T, E> SumType2 for Result<T, E> {
type Type1 = T;
type Type2 = E;
#[inline]
fn from_type1(val: Self::Type1) -> Self {
Ok(val)
}
#[inline]
fn from_type2(val: Self::Type2) -> Self {
Err(val)
}
#[inline]
fn is_type1(&self) -> bool {
self.is_ok()
}
#[inline]
fn is_type2(&self) -> bool {
self.is_err()
}
#[inline]
fn into_type1(self) -> Option<Self::Type1> {
self.ok()
}
#[inline]
fn into_type2(self) -> Option<Self::Type2> {
self.err()
}
}
#[cfg(feature = "either")]
impl<L, R> SumType2 for Either<L, R> {
type Type1 = L;
type Type2 = R;
#[inline]
fn from_type1(val: Self::Type1) -> Self {
Either::Left(val)
}
#[inline]
fn from_type2(val: Self::Type2) -> Self {
Either::Right(val)
}
#[inline]
fn is_type1(&self) -> bool {
self.is_left()
}
#[inline]
fn is_type2(&self) -> bool {
self.is_right()
}
#[inline]
fn into_type1(self) -> Option<Self::Type1> {
self.left()
}
#[inline]
fn into_type2(self) -> Option<Self::Type2> {
self.right()
}
}
pub trait ObserveResult {
fn is_callback_alive(self) -> bool;
}
impl ObserveResult for () {
#[inline]
fn is_callback_alive(self) -> bool {
true
}
}
impl ObserveResult for bool {
#[inline]
fn is_callback_alive(self) -> bool {
self
}
}
impl<T> ObserveResult for Option<T> {
#[inline]
fn is_callback_alive(self) -> bool {
self.is_some()
}
}
impl<T, E> ObserveResult for Result<T, E> {
#[inline]
fn is_callback_alive(self) -> bool {
self.is_ok()
}
}