pub struct EvaluatorCache<R> { /* private fields */ }Expand description
A reusable memory buffer for expression evaluation.
When evaluating an expression multiple times (e.g., against different rows in a database),
allocating new vectors for every calculation is inefficient. EvaluatorCache holds onto
the allocated memory between runs.
Use this to avoid repeated allocations when evaluating the same expression multiple times.
§Automatic Invalidation
This struct stores a version UUID of the expression it was last used with. If you pass
this cache to evaluate_with on a modified or completely different expression, it will
automatically detect the mismatch and clear itself.
§Memory & Performance
- Allocations: Reuses internal vectors to minimize heap traffic.
- Cloning: When
evaluate_withreturns, the final results for the roots are cloned from this cache.- If your result type
Ris large (e.g., a 10MB Bitmap or large Vector), this clone can be expensive. - Recommendation: Wrap large results in
std::sync::Arcorstd::rc::Rcso that cloning is cheap (pointer copy) rather than deep.
- If your result type
§Example
use logify::{EvaluatorCache, ExpressionBuilder, Evaluator};
// Setup
let mut cache = EvaluatorCache::new();
let mut solver = Solver;
// Build a simple expression
let builder = ExpressionBuilder::new();
builder.add_root(builder.leaf("A"));
let expr = builder.build();
let dataset = vec!["Row1", "Row2", "Row3"];
// Fast: Reuses the same vectors for every iteration
for item in dataset {
// In a real scenario, you would update the roots or append expressions each time.
let result = expr.evaluate_with(&mut solver, &mut cache);
}Implementations§
Trait Implementations§
Source§impl<R> Default for EvaluatorCache<R>
impl<R> Default for EvaluatorCache<R>
Source§impl<'de, R> Deserialize<'de> for EvaluatorCache<R>where
R: Deserialize<'de>,
impl<'de, R> Deserialize<'de> for EvaluatorCache<R>where
R: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<R> Freeze for EvaluatorCache<R>
impl<R> RefUnwindSafe for EvaluatorCache<R>where
R: RefUnwindSafe,
impl<R> Send for EvaluatorCache<R>where
R: Send,
impl<R> Sync for EvaluatorCache<R>where
R: Sync,
impl<R> Unpin for EvaluatorCache<R>where
R: Unpin,
impl<R> UnwindSafe for EvaluatorCache<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more