use std::{borrow::Borrow, marker::PhantomData}; use graphene_core::Node; #[derive(Default)] pub struct AddNode(PhantomData); impl Node for AddNode { type Output<'a> = ::Output; type Input<'a> = (T, T); fn eval<'a, I: Borrow>>(&'a self, input: I) -> T::Output { input.borrow().0 + input.borrow().1 } } #[derive(Default)] /// Destructures a Tuple of two values and returns the first one pub struct FstNode(PhantomData, PhantomData); impl Node for FstNode { type Output<'a> = &'a T where Self: 'a; type Input<'a> = &'a (T, U) where Self: 'a; fn eval<'a, I: Borrow>>(&'a self, input: I) -> Self::Output<'a> { let &(ref a, _) = input.borrow(); a } } #[derive(Default)] /// Destructures a Tuple of two values and returns the first one pub struct SndNode(PhantomData, PhantomData); impl Node for SndNode { type Output<'a> = &'a U where Self: 'a; type Input<'a> = &'a (T, U) where Self: 'a; fn eval<'a, I: Borrow>>(&'a self, input: I) -> Self::Output<'a> { let &(_, ref b) = input.borrow(); b } }