Skip to main content

Runtime

Trait Runtime 

Source
pub trait Runtime: Send + Sync {
    // Required methods
    fn lang(&self) -> &str;
    fn evaluate(
        &self,
        descriptor: &FunctionDescriptor,
        cell: &Cell,
        inputs: &mut dyn Inputs,
        budget: &mut Budget,
    ) -> Result<Scalar, EvalError>;

    // Provided method
    fn asof_dependent(&self, descriptor: &FunctionDescriptor) -> bool { ... }
}
Expand description

The evaluator of one function language (code.lang of a descriptor).

evaluate computes the value of cell (a cell of the function descriptor describes; cell.fn_hash is the descriptor’s hash) from the cell’s arguments and from the values of other cells, which it reads through inputs. It must be a pure function of those (and of Inputs::asof for an asof-dependent function): no clock, no randomness, no I/O. It charges its work to budget and propagates every error inputs and budget return (see EvalError); it may catch an EvalError::Fault its language lets it catch.

It may be called more than once for one cell in one request: when it reads an input that is not available yet, the read returns EvalError::Suspended, the engine evaluates the input, then calls evaluate again from the start (reads already made are then answered at once). So evaluate must not have side effects either. Each call is an attempt with a budget meter of its own: the fuel of a cell’s evaluation is that of its last, completed call (Budget).

Required Methods§

Source

fn lang(&self) -> &str

The language this runtime evaluates: a name (SPEC 2.2), e.g. formula. stored is the engine’s own (a lookup) and cannot be configured.

Source

fn evaluate( &self, descriptor: &FunctionDescriptor, cell: &Cell, inputs: &mut dyn Inputs, budget: &mut Budget, ) -> Result<Scalar, EvalError>

The value of cell, whose type must be the descriptor’s declared return type; or EvalError::Fault: the cell has no value (SPEC 15.12).

Provided Methods§

Source

fn asof_dependent(&self, descriptor: &FunctionDescriptor) -> bool

Whether the function is asof-dependent (SPEC 15.12: its body uses asof() or a bounded latest), derived from the descriptor alone. Its receipts then have the evaluation asof as their asof, one per requested asof, and the engine never reuses one for another asof, from the memo or from the store. Provided: false.

A function that reads Inputs::asof is treated as asof-dependent for that evaluation even when this says false; its receipt is then not kept as a computed version (a later request could not tell it apart), so declaring it is cheaper.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§