mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
Add Unit and Id nodes to node graph
This commit is contained in:
parent
a2703c0fb1
commit
998f37d1b0
2 changed files with 32 additions and 6 deletions
|
@ -22,12 +22,12 @@ impl<'n, T: Fn(<N as Node<'n>>::Output) -> O, N: Node<'n>, O> FnNode<'n, T, N, O
|
|||
|
||||
pub struct FnNodeWithState<
|
||||
'n,
|
||||
T: Fn(<N as Node<'n>>::Output, &State) -> O,
|
||||
T: Fn(<N as Node<'n>>::Output, &'n State) -> O,
|
||||
N: Node<'n>,
|
||||
O,
|
||||
State: 'n,
|
||||
>(T, N, State, PhantomData<&'n O>);
|
||||
impl<'n, T: Fn(<N as Node<'n>>::Output, &State) -> O, N: Node<'n>, O: 'n, State> Node<'n>
|
||||
impl<'n, T: Fn(<N as Node<'n>>::Output, &'n State) -> O, N: Node<'n>, O: 'n, State: 'n> Node<'n>
|
||||
for FnNodeWithState<'n, T, N, O, State>
|
||||
{
|
||||
type Output = O;
|
||||
|
@ -37,7 +37,9 @@ impl<'n, T: Fn(<N as Node<'n>>::Output, &State) -> O, N: Node<'n>, O: 'n, State>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'n, T: Fn(N::Output, &State) -> O, N: Node<'n>, O, State> FnNodeWithState<'n, T, N, O, State> {
|
||||
impl<'n, T: Fn(<N as Node<'n>>::Output, &'n State) -> O, N: Node<'n>, O: 'n, State: 'n>
|
||||
FnNodeWithState<'n, T, N, O, State>
|
||||
{
|
||||
pub fn new(f: T, input: N, state: State) -> Self {
|
||||
FnNodeWithState(f, input, state, PhantomData)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'n, T, U: 'n, N: Node<'n, Output = (T, U)>> Node<'n> for SndNode<'n, N> {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
/// Destructures a Tuple of two values and returns the first one
|
||||
/// Return a tuple with two instances of the input argument
|
||||
pub struct DupNode<'n, N: Node<'n>>(N, PhantomData<&'n ()>);
|
||||
impl<'n, N: Node<'n>> Node<'n> for DupNode<'n, N> {
|
||||
type Output = (N::Output, N::Output);
|
||||
|
@ -57,15 +57,39 @@ impl<'n, N: Node<'n>> Node<'n> for DupNode<'n, N> {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/// Return the unit value
|
||||
pub struct UnitNode;
|
||||
impl<'n> Node<'n> for UnitNode {
|
||||
type Output = ();
|
||||
fn eval(&'n self) -> Self::Output {}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/// Return the Input Argument
|
||||
pub struct IdNode<'n, N: Node<'n>>(N, PhantomData<&'n ()>);
|
||||
impl<'n, N: Node<'n>> Node<'n> for IdNode<'n, N> {
|
||||
type Output = N::Output;
|
||||
fn eval(&'n self) -> Self::Output {
|
||||
self.0.eval()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn foo() {
|
||||
let value = crate::value::ValueNode::new(2u32);
|
||||
let unit = UnitNode;
|
||||
let value = IdNode(crate::value::ValueNode::new(2u32), PhantomData);
|
||||
let value2 = crate::value::ValueNode::new(4u32);
|
||||
let dup = DupNode(value, PhantomData);
|
||||
let dup = DupNode(&value, PhantomData);
|
||||
fn int(_: (), state: &u32) -> &u32 {
|
||||
state
|
||||
}
|
||||
fn swap<'n>(input: (&'n u32, &'n u32)) -> (&'n u32, &'n u32) {
|
||||
(input.1, input.0)
|
||||
}
|
||||
let fnn = crate::generic::FnNode::new(swap, &dup);
|
||||
let fns = crate::generic::FnNodeWithState::new(int, &unit, 42u32);
|
||||
let _ = fnn.eval();
|
||||
let _ = fns.eval();
|
||||
let snd = SndNode(&fnn, PhantomData);
|
||||
let _ = snd.eval();
|
||||
let add = AddNode(&snd, value2, PhantomData);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue