Simplify node trait definition (#1146)

* Simplify node trait
This commit is contained in:
Dennis Kobert
2023-04-17 23:42:22 +02:00
committed by Keavon Chambers
parent 1d6c4f13dd
commit 76c754d38a
11 changed files with 47 additions and 105 deletions

View File

@@ -5,7 +5,7 @@ pub struct FnNode<T: Fn(I) -> O, I, O>(T, PhantomData<(I, O)>);
impl<'i, T: Fn(I) -> O + 'i, O: 'i, I: 'i> Node<'i, I> for FnNode<T, I, O> {
type Output = O;
fn eval<'s: 'i>(&'s self, input: I) -> Self::Output {
fn eval(&'i self, input: I) -> Self::Output {
self.0(input)
}
}
@@ -19,11 +19,11 @@ impl<T: Fn(I) -> O, I, O> FnNode<T, I, O> {
pub struct FnNodeWithState<'i, T: Fn(I, &'i State) -> O, I, O, State: 'i>(T, State, PhantomData<(&'i O, I)>);
impl<'i, I: 'i, O: 'i, State, T: Fn(I, &'i State) -> O + 'i> Node<'i, I> for FnNodeWithState<'i, T, I, O, State> {
type Output = O;
fn eval<'s: 'i>(&'s self, input: I) -> Self::Output {
fn eval(&'i self, input: I) -> Self::Output {
(self.0)(input, &self.1)
}
}
impl<'i, 's: 'i, I, O, State, T: Fn(I, &'i State) -> O> FnNodeWithState<'i, T, I, O, State> {
impl<'i, I, O, State, T: Fn(I, &'i State) -> O> FnNodeWithState<'i, T, I, O, State> {
pub fn new(f: T, state: State) -> Self {
FnNodeWithState(f, state, PhantomData)
}