EvaluatorCache

Struct EvaluatorCache 

Source
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_with returns, the final results for the roots are cloned from this cache.
    • If your result type R is large (e.g., a 10MB Bitmap or large Vector), this clone can be expensive.
    • Recommendation: Wrap large results in std::sync::Arc or std::rc::Rc so that cloning is cheap (pointer copy) rather than deep.

§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§

Source§

impl<R> EvaluatorCache<R>

Source

pub fn new() -> Self

Creates a new, empty cache.

Source

pub fn clear(&mut self)

Manually clears the internal buffers and resets the versioning.

Usually not necessary, as evaluate_with handles invalidation automatically.

Trait Implementations§

Source§

impl<R> Default for EvaluatorCache<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<R> Serialize for EvaluatorCache<R>
where R: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,