mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 10:58:04 +08:00
Implement node registry (#822)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use core::marker::PhantomData;
|
||||
use core::ops::Add;
|
||||
|
||||
use crate::Node;
|
||||
use crate::{Node, RefNode};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct AddNode;
|
||||
@@ -153,18 +153,24 @@ impl<'n, T: Clone + 'n> Node<T> for DupNode {
|
||||
/// Return the Input Argument
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct IdNode;
|
||||
impl<'n, T: 'n> Node<T> for IdNode {
|
||||
impl<T> Node<T> for IdNode {
|
||||
type Output = T;
|
||||
fn eval(self, input: T) -> Self::Output {
|
||||
input
|
||||
}
|
||||
}
|
||||
impl<'n, T: 'n> Node<T> for &'n IdNode {
|
||||
impl<'n, T> Node<T> for &'n IdNode {
|
||||
type Output = T;
|
||||
fn eval(self, input: T) -> Self::Output {
|
||||
input
|
||||
}
|
||||
}
|
||||
impl<T> RefNode<T> for IdNode {
|
||||
type Output = T;
|
||||
fn eval_ref(&self, input: T) -> Self::Output {
|
||||
input
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MapResultNode<MN, I, E>(pub MN, pub PhantomData<(I, E)>);
|
||||
|
||||
@@ -177,7 +183,7 @@ impl<MN: Node<I>, I, E> Node<Result<I, E>> for MapResultNode<MN, I, E> {
|
||||
impl<'n, MN: Node<I> + Copy, I, E> Node<Result<I, E>> for &'n MapResultNode<MN, I, E> {
|
||||
type Output = Result<MN::Output, E>;
|
||||
fn eval(self, input: Result<I, E>) -> Self::Output {
|
||||
input.map(|x| (&self.0).eval(x))
|
||||
input.map(|x| self.0.eval(x))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user