use std::any::Any;
use annotate::Function;
use crate::PhlowView;
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct DefiningMethod(Function);
impl DefiningMethod {
pub fn as_view<T: Any>(&self, object: &T) -> Box<dyn PhlowView> {
self.0
.call::<fn(&dyn Any, DefiningMethod) -> Box<dyn PhlowView>, _>(|method| {
method(object, self.clone())
})
}
pub fn as_view_for_any(&self, object: &dyn Any) -> Box<dyn PhlowView> {
self.0
.call::<fn(&dyn Any, DefiningMethod) -> Box<dyn PhlowView>, _>(|method| {
method(object, self.clone())
})
}
pub const fn name(&self) -> &'static str {
self.0.name()
}
}
impl From<Function> for DefiningMethod {
fn from(value: Function) -> Self {
Self(value)
}
}