Fix formatting of previous commit

This commit is contained in:
Keavon Chambers
2022-08-04 00:18:42 -07:00
parent d09f023618
commit 0c2dbd411b
11 changed files with 226 additions and 234 deletions

View File

@@ -4,36 +4,36 @@ use std::marker::PhantomData;
/// Caches the output of a given Node and acts as a proxy
pub struct CacheNode<'n, CachedNode: Node<'n>> {
node: CachedNode,
cache: OnceCell<CachedNode::Output>,
_phantom: PhantomData<&'n ()>,
node: CachedNode,
cache: OnceCell<CachedNode::Output>,
_phantom: PhantomData<&'n ()>,
}
impl<'n, CashedNode: Node<'n>> Node<'n> for CacheNode<'n, CashedNode>
where
CashedNode::Output: 'n,
CashedNode::Output: 'n,
{
type Output = &'n CashedNode::Output;
fn eval(&'n self) -> Self::Output {
self.cache.get_or_init(|| self.node.eval())
}
type Output = &'n CashedNode::Output;
fn eval(&'n self) -> Self::Output {
self.cache.get_or_init(|| self.node.eval())
}
}
impl<'n, CachedNode: Node<'n>> CacheNode<'n, CachedNode> {
pub fn clear(&'n mut self) {
self.cache = OnceCell::new();
}
pub fn new(node: CachedNode) -> CacheNode<'n, CachedNode> {
CacheNode {
node,
cache: OnceCell::new(),
_phantom: PhantomData,
}
}
pub fn clear(&'n mut self) {
self.cache = OnceCell::new();
}
pub fn new(node: CachedNode) -> CacheNode<'n, CachedNode> {
CacheNode {
node,
cache: OnceCell::new(),
_phantom: PhantomData,
}
}
}
impl<'n, CachedNode: Node<'n>> Cache for CacheNode<'n, CachedNode> {
fn clear(&mut self) {
self.cache = OnceCell::new();
}
fn clear(&mut self) {
self.cache = OnceCell::new();
}
}
/*use dyn_any::{DynAny, StaticType};