mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Replace GAT with lifetime on trait in node graph
This commit is contained in:
@@ -1,25 +1,23 @@
|
||||
use graphene_core::{ExecPtr, Node};
|
||||
use graphene_core::Node;
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::{any::Any, borrow::Borrow, ops::Deref};
|
||||
|
||||
/// Caches the output of a given Node and acts as a proxy
|
||||
pub struct CacheNode<'n, 'c, CachedNode: Node + 'c> {
|
||||
pub struct CacheNode<'n, CachedNode: Node<'n, Input>, Input> {
|
||||
node: &'n CachedNode,
|
||||
cache: OnceCell<CachedNode::Output<'c>>,
|
||||
cache: OnceCell<CachedNode::Output>,
|
||||
}
|
||||
impl<'n: 'c, 'c, CashedNode: Node> Node for CacheNode<'n, 'c, CashedNode> {
|
||||
type Output<'a> = &'a CashedNode::Output<'c> where 'c: 'a;
|
||||
type Input<'a> = CashedNode::Input<'c> where 'c: 'a;
|
||||
fn eval<'a, I: Borrow<Self::Input<'a>>>(&'a self, input: I) -> Self::Output<'a> {
|
||||
impl<'n, CashedNode: Node<'n, Input>, Input> Node<'n, Input> for CacheNode<'n, CashedNode, Input> {
|
||||
type Output = &'n CashedNode::Output;
|
||||
fn eval(&'n self, input: &'n Input) -> Self::Output {
|
||||
self.cache.get_or_init(|| self.node.eval(input))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, 'c, CachedNode: Node> CacheNode<'n, 'c, CachedNode> {
|
||||
impl<'n, CachedNode: Node<'n, Input>, Input> CacheNode<'n, CachedNode, Input> {
|
||||
pub fn clear(&'n mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
pub fn new(node: &'n CachedNode) -> CacheNode<'n, 'c, CachedNode> {
|
||||
pub fn new(node: &'n CachedNode) -> CacheNode<'n, CachedNode, Input> {
|
||||
CacheNode {
|
||||
node,
|
||||
cache: OnceCell::new(),
|
||||
|
||||
Reference in New Issue
Block a user