use crate::extension::ExtDTypeAdapter;
use crate::extension::ExtDTypeRef;
use crate::extension::ExtDTypeVTable;
pub trait Matcher {
type Match<'a>;
fn matches(item: &ExtDTypeRef) -> bool {
Self::try_match(item).is_some()
}
fn try_match<'a>(item: &'a ExtDTypeRef) -> Option<Self::Match<'a>>;
}
impl<V: ExtDTypeVTable> Matcher for V {
type Match<'a> = &'a V::Metadata;
fn matches(item: &ExtDTypeRef) -> bool {
item.0.as_any().is::<ExtDTypeAdapter<V>>()
}
fn try_match<'a>(item: &'a ExtDTypeRef) -> Option<Self::Match<'a>> {
item.0
.as_any()
.downcast_ref::<ExtDTypeAdapter<V>>()
.map(|adapter| &adapter.metadata)
}
}