Remove input from the node definition

This commit is contained in:
Dennis
2022-06-05 01:15:22 +02:00
committed by Keavon Chambers
parent aa5e6f43f6
commit 4b8c0ec4e1
4 changed files with 99 additions and 84 deletions

View File

@@ -3,33 +3,33 @@ use core::marker::PhantomData;
use crate::Node;
pub struct IntNode<const N: u32>;
impl<'n, const N: u32> Node<'n, ()> for IntNode<N> {
impl<'n, const N: u32> Node<'n> for IntNode<N> {
type Output = u32;
fn eval(&self, _input: ()) -> u32 {
fn eval(&self) -> u32 {
N
}
}
#[derive(Default)]
pub struct ValueNode<'n, T>(T, PhantomData<&'n ()>);
impl<'n, T: 'n> Node<'n, ()> for ValueNode<'n, T> {
pub struct ValueNode<T>(pub T);
impl<'n, T: 'n> Node<'n> for ValueNode<T> {
type Output = &'n T;
fn eval(&self, _input: ()) -> &T {
fn eval(&'n self) -> Self::Output {
&self.0
}
}
impl<'n, T> ValueNode<'n, T> {
pub const fn new(value: T) -> ValueNode<'n, T> {
ValueNode(value, PhantomData)
impl<'n, T> ValueNode<T> {
pub const fn new(value: T) -> ValueNode<T> {
ValueNode(value)
}
}
#[derive(Default)]
pub struct DefaultNode<T>(PhantomData<T>);
impl<'n, T: Default + 'n> Node<'n, ()> for DefaultNode<T> {
impl<'n, T: Default + 'n> Node<'n> for DefaultNode<T> {
type Output = T;
fn eval(&self, _input: ()) -> T {
fn eval(&self) -> T {
T::default()
}
}
@@ -38,16 +38,3 @@ impl<T> DefaultNode<T> {
DefaultNode(PhantomData)
}
}
pub struct DefaultRefNode<'n, T>(ValueNode<'n, T>);
impl<'n, T: 'n> Node<'n, ()> for DefaultRefNode<'n, T> {
type Output = &'n T;
fn eval(&'n self, _input: ()) -> &'n T {
self.0.eval(())
}
}
impl<'n, T: Default> Default for DefaultRefNode<'n, T> {
fn default() -> DefaultRefNode<'n, T> {
DefaultRefNode(ValueNode::new(T::default()))
}
}