Expression

Trait Expression 

Source
pub trait Expression:
    Send
    + Sync
    + Debug
    + DynClone {
    // Required methods
    fn resolve(&self, ctx: &mut Context<'_>) -> Resolved;
    fn type_info(&self, state: &TypeState) -> TypeInfo;

    // Provided methods
    fn resolve_constant(&self, _state: &TypeState) -> Option<Value> { ... }
    fn type_def(&self, state: &TypeState) -> TypeDef { ... }
    fn apply_type_info(&self, state: &mut TypeState) -> TypeDef { ... }
    fn format(&self) -> Option<String> { ... }
}

Required Methods§

Source

fn resolve(&self, ctx: &mut Context<'_>) -> Resolved

Resolve an expression to a concrete Value.

This method is executed at runtime.

An expression is allowed to fail, which aborts the running program.

Source

fn type_info(&self, state: &TypeState) -> TypeInfo

Calculates the type state after an expression resolves, including the expression result itself. This must be called with the initial TypeState.

Consider using apply_type_info instead if you want to just access the expr result type, while updating an existing state.

Provided Methods§

Source

fn resolve_constant(&self, _state: &TypeState) -> Option<Value>

Resolve an expression to a value without any context, if possible. This attempts to resolve expressions using only compile-time information.

This returns Some for static expressions, or None for dynamic expressions.

Source

fn type_def(&self, state: &TypeState) -> TypeDef

Resolve an expression to its TypeDef type definition. This must be called with the initial TypeState.

Consider calling type_info instead if you want to capture changes in the type state from side-effects.

Source

fn apply_type_info(&self, state: &mut TypeState) -> TypeDef

Applies state changes from the expression to the given state, and returns the result type.

Source

fn format(&self) -> Option<String>

Format the expression into a consistent style.

This defaults to not formatting, so that function implementations don’t need to care about formatting (this is handled by the internal function call expression).

Implementors§