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

@ -27,7 +27,7 @@ where
N: for<'any_input> Node<'any_input, _I, Output = &'any_input _O>,
{
type Output = Any<'input>;
fn eval<'node: 'input>(&'node self, input: Any<'input>) -> Self::Output {
fn eval(&'input self, input: Any<'input>) -> Self::Output {
{
let node_name = core::any::type_name::<N>();
let input: Box<_I> = dyn_any::downcast(input).unwrap_or_else(|e| panic!("DynAnyRefNode Input, {e} in:\n{node_name}"));
@ -54,7 +54,7 @@ where
N: for<'any_input> Node<'any_input, &'any_input _I, Output = _O>,
{
type Output = Any<'input>;
fn eval<'node: 'input>(&'node self, input: Any<'input>) -> Self::Output {
fn eval(&'input self, input: Any<'input>) -> Self::Output {
{
let node_name = core::any::type_name::<N>();
let input: Box<&_I> = dyn_any::downcast(input).unwrap_or_else(|e| panic!("DynAnyInRefNode Input, {e} in:\n{node_name}"));
@ -113,7 +113,7 @@ pub struct DowncastBothNode<'a, I, O> {
impl<'n: 'input, 'input, O: 'input + StaticType, I: 'input + StaticType> Node<'input, I> for DowncastBothNode<'n, I, O> {
type Output = O;
#[inline]
fn eval<'node: 'input>(&'node self, input: I) -> Self::Output {
fn eval(&'input self, input: I) -> Self::Output {
{
let input = Box::new(input);
let out = dyn_any::downcast(self.node.eval(input)).unwrap_or_else(|e| panic!("DowncastBothNode Input {e}"));
@ -140,7 +140,7 @@ pub struct DowncastBothRefNode<'a, I, O> {
impl<'n: 'input, 'input, O: 'input + StaticType, I: 'input + StaticType> Node<'input, I> for DowncastBothRefNode<'n, I, O> {
type Output = &'input O;
#[inline]
fn eval<'node: 'input>(&'node self, input: I) -> Self::Output {
fn eval(&'input self, input: I) -> Self::Output {
{
let input = Box::new(input);
let out: Box<&_> = dyn_any::downcast::<&O>(self.node.eval(input)).unwrap_or_else(|e| panic!("DowncastBothRefNode Input {e}"));
@ -161,7 +161,7 @@ pub struct ComposeTypeErased<'a> {
impl<'i, 'a: 'i> Node<'i, Any<'i>> for ComposeTypeErased<'a> {
type Output = Any<'i>;
fn eval<'s: 'i>(&'s self, input: Any<'i>) -> Self::Output {
fn eval(&'i self, input: Any<'i>) -> Self::Output {
let arg = self.first.eval(input);
self.second.eval(arg)
}

View file

@ -19,7 +19,7 @@ where
CachedNode: for<'any_input> Node<'any_input, I, Output = T>,
{
type Output = &'i T;
fn eval<'s: 'i>(&'s self, input: I) -> Self::Output {
fn eval(&'i self, input: I) -> Self::Output {
let mut hasher = Xxh3::new();
input.hash(&mut hasher);
let hash = hasher.finish();
@ -63,7 +63,7 @@ pub struct LetNode<T> {
}
impl<'i, T: 'i + Hash> Node<'i, Option<T>> for LetNode<T> {
type Output = &'i T;
fn eval<'s: 'i>(&'s self, input: Option<T>) -> Self::Output {
fn eval(&'i self, input: Option<T>) -> Self::Output {
match input {
Some(input) => {
let mut hasher = Xxh3::new();
@ -108,7 +108,7 @@ where
Input: Node<'i, ()>,
{
type Output = <Input>::Output;
fn eval<'s: 'i>(&'s self, _: &'i T) -> Self::Output {
fn eval(&'i self, _: &'i T) -> Self::Output {
self.input.eval(())
}
}
@ -131,7 +131,7 @@ where
Let: for<'a> Node<'a, Option<T>, Output = &'a T>,
{
type Output = &'i T;
fn eval<'s: 'i>(&'s self, _: ()) -> Self::Output {
fn eval(&'i self, _: ()) -> Self::Output {
self.let_node.eval(None)
}
}