#![warn(missing_docs)]
#![doc = include_str!("../README.md")]
use std::{rc::Rc, sync::Arc};
pub use poly_enum_derive::PolyEnum;
pub trait PolyEnum<T> {
fn cast(self) -> Option<T>;
}
impl<T, U> PolyEnum<Arc<U>> for Arc<T> where T: Clone + PolyEnum<U> {
fn cast(self) -> Option<Arc<U>> {
Arc::unwrap_or_clone(self).cast().map(Arc::new)
}
}
impl<T, U> PolyEnum<Box<U>> for Box<T> where T: PolyEnum<U> {
fn cast(self) -> Option<Box<U>> {
(*self).cast().map(Box::new)
}
}
impl<T, U> PolyEnum<Rc<U>> for Rc<T> where T: Clone + PolyEnum<U> {
fn cast(self) -> Option<Rc<U>> {
Rc::unwrap_or_clone(self).cast().map(Rc::new)
}
}
impl<T, U> PolyEnum<Vec<U>> for Vec<T> where T: PolyEnum<U> {
fn cast(self) -> Option<Vec<U>> {
self.into_iter().map(|e| e.cast()).collect::<Option<Vec<_>>>()
}
}