#![no_std] #![cfg_attr(target_arch = "spirv", feature(register_attr), register_attr(spirv))] #[cfg(feature = "async")] extern crate alloc; #[cfg(feature = "async")] use alloc::boxed::Box; #[cfg(feature = "async")] use async_trait::async_trait; pub mod generic; pub mod ops; pub mod raster; pub mod structural; pub mod value; pub trait Node { type Output; fn eval(self, input: T) -> Self::Output; fn input(&self) -> &str { core::any::type_name::() } fn output(&self) -> &str { core::any::type_name::() } } trait Input { unsafe fn input(&self, input: I); } pub trait RefNode { type Output; fn eval_ref(&self, input: T) -> Self::Output; } impl<'n, N: 'n, I> RefNode for &'n N where &'n N: Node, Self: 'n, { type Output = <&'n N as Node>::Output; fn eval_ref(&self, input: I) -> Self::Output { self.eval(input) } } pub trait AsRefNode<'n, T> where &'n Self: Node, Self: 'n, { type Output; fn eval_box(&'n self, input: T) -> ::Output; } impl<'n, N: 'n, I> AsRefNode<'n, I> for N where &'n N: Node, N: Node, Self: 'n, { type Output = <&'n N as Node>::Output; fn eval_box(&'n self, input: I) -> ::Output { self.eval(input) } } impl<'n, T> Node for &'n (dyn AsRefNode<'n, T, Output = T> + 'n) { type Output = T; fn eval(self, input: T) -> Self::Output { self.eval_box(input) } } #[cfg(feature = "async")] #[async_trait] pub trait AsyncNode { type Output; async fn eval_async(self, input: T) -> Self::Output; } /*#[cfg(feature = "async")] #[async_trait] impl<'n, N: Node + Send + Sync + 'n, T: Send + 'n> AsyncNode for N { type Output = N::Output; async fn eval_async(self, input: T) -> Self::Output { Node::eval(self, input) } }*/ pub trait Cache { fn clear(&mut self); } #[cfg(feature = "async")] impl Node for Box where N: Node, { type Output = >::Output; fn eval(self, input: I) -> Self::Output { (*self).eval(input) } } #[cfg(feature = "async")] impl<'n, N, I> Node for &'n Box where &'n N: Node, { type Output = <&'n N as Node>::Output; fn eval(self, input: I) -> Self::Output { self.as_ref().eval(input) } }