use std::{borrow::Borrow, marker::PhantomData}; use crate::Node; pub struct FnNode O, In, O>(T, PhantomData, PhantomData); impl O, In, O> Node for FnNode { type Output<'a> = O where Self: 'a; type Input<'a> = In where Self: 'a; fn eval<'a, I: Borrow>>(&'a self, input: I) -> Self::Output<'a> { self.0(input.borrow()) } } impl O, In, O> FnNode { pub fn new(f: T) -> Self { FnNode(f, PhantomData::default(), PhantomData::default()) } } pub struct FnNodeWithState O, In, O, State>( T, State, PhantomData, PhantomData, ); impl O, In, O, State> Node for FnNodeWithState { type Output<'a> = O where Self: 'a; type Input<'a> = In where Self: 'a; fn eval<'a, I: Borrow>>(&'a self, input: I) -> Self::Output<'a> { self.0(input.borrow(), &self.1) } } impl O, In, O, State> FnNodeWithState { pub fn new(f: T, state: State) -> Self { FnNodeWithState(f, state, PhantomData::default(), PhantomData::default()) } }