use graphene_core::{Cache, Node}; use once_cell::sync::OnceCell; /// Caches the output of a given Node and acts as a proxy pub struct CacheNode, I> { node: CachedNode, cache: OnceCell, } impl<'n, CashedNode: Node + Copy, I> Node for &'n CacheNode { type Output = &'n CashedNode::Output; fn eval(self, input: I) -> Self::Output { self.cache.get_or_init(|| self.node.eval(input)) } } impl<'n, CachedNode: Node, I> CacheNode { pub fn clear(&'n mut self) { self.cache = OnceCell::new(); } pub fn new(node: CachedNode) -> CacheNode { CacheNode { node, cache: OnceCell::new() } } } impl, I> Cache for CacheNode { fn clear(&mut self) { self.cache = OnceCell::new(); } } /*use dyn_any::{DynAny, StaticType}; #[derive(DynAny)] struct Boo<'a>(&'a u8); */