mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-02 12:32:17 +00:00
Try and fail to make nodes object-safe in node graph
This commit is contained in:
parent
800fb4dbc1
commit
3243b80cf2
12 changed files with 200 additions and 64 deletions
37
node-graph/gcore/src/ops.rs
Normal file
37
node-graph/gcore/src/ops.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use std::{borrow::Borrow, marker::PhantomData};
|
||||
|
||||
use crate::Node;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AddNode<T>(PhantomData<T>);
|
||||
impl<T: std::ops::Add + 'static + Copy> Node for AddNode<T> {
|
||||
type Output<'a> = <T as std::ops::Add>::Output;
|
||||
type Input<'a> = (T, T);
|
||||
fn eval<'a, I: Borrow<Self::Input<'a>>>(&'a self, input: I) -> T::Output {
|
||||
input.borrow().0 + input.borrow().1
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
/// Destructures a Tuple of two values and returns the first one
|
||||
pub struct FstNode<T, U>(PhantomData<T>, PhantomData<U>);
|
||||
impl<T: Copy, U> Node for FstNode<T, U> {
|
||||
type Output<'a> = &'a T where Self: 'a;
|
||||
type Input<'a> = &'a (T, U) where Self: 'a;
|
||||
fn eval<'a, I: Borrow<Self::Input<'a>>>(&'a self, input: I) -> Self::Output<'a> {
|
||||
let &(ref a, _) = input.borrow();
|
||||
a
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
/// Destructures a Tuple of two values and returns the first one
|
||||
pub struct SndNode<T, U>(PhantomData<T>, PhantomData<U>);
|
||||
impl<T, U: Copy> Node for SndNode<T, U> {
|
||||
type Output<'a> = &'a U where Self: 'a;
|
||||
type Input<'a> = &'a (T, U) where Self: 'a;
|
||||
fn eval<'a, I: Borrow<Self::Input<'a>>>(&'a self, input: I) -> Self::Output<'a> {
|
||||
let &(_, ref b) = input.borrow();
|
||||
b
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue