From f8d4e10f35d0464065124291170bcc0158321097 Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 2 Apr 2022 12:48:05 +0200 Subject: [PATCH] Add Exec trait to simplify calling nodes without input data --- node-graph/src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/node-graph/src/main.rs b/node-graph/src/main.rs index 7421f591..01063e16 100644 --- a/node-graph/src/main.rs +++ b/node-graph/src/main.rs @@ -53,6 +53,16 @@ pub trait After: Sized { } impl After for Second {} +pub trait Exec: Node +where + for<'a> &'a (): Borrow<::Input<'a>>, +{ + fn exec(&self) -> Self::Output<'_> { + self.eval(&()) + } +} +impl Exec for T where for<'a> &'a (): Borrow<::Input<'a>> {} + pub trait DynamicInput { fn set_kwarg_by_name(&mut self, name: &str, value: &dyn Any); fn set_arg_by_index(&mut self, index: usize, value: &dyn Any); @@ -60,7 +70,7 @@ pub trait DynamicInput { fn main() { let int = IntNode::<32>; - let add: u32 = AddNode::::default().eval((int.eval(&()), int.eval(&()))); + let add: u32 = AddNode::::default().eval((int.exec(), int.exec())); let fnode = FnNode::new(|(a, b): &(i32, i32)| a - b); //let sub = fnode.any(&("a", 2)); let cache = CacheNode::new(&fnode);