Trait rsjsonnet_lang::program::Callbacks

source ·
pub trait Callbacks {
    // Required methods
    fn import(
        &mut self,
        program: &mut Program,
        from: SpanId,
        path: &str,
    ) -> Result<Thunk, ImportError>;
    fn import_str(
        &mut self,
        program: &mut Program,
        from: SpanId,
        path: &str,
    ) -> Result<String, ImportError>;
    fn import_bin(
        &mut self,
        program: &mut Program,
        from: SpanId,
        path: &str,
    ) -> Result<Vec<u8>, ImportError>;
    fn trace(
        &mut self,
        program: &mut Program,
        message: &str,
        stack: &[EvalStackTraceItem],
    );
    fn native_call(
        &mut self,
        program: &mut Program,
        name: &InternedStr,
        args: &[Value],
    ) -> Result<Value, NativeError>;
}
Expand description

Trait to customize the behavior of operations during evaluation.

Some Program methods need to be provided with an implementor of this trait.

Required Methods§

source

fn import( &mut self, program: &mut Program, from: SpanId, path: &str, ) -> Result<Thunk, ImportError>

Called when an import expression is evaluated.

source

fn import_str( &mut self, program: &mut Program, from: SpanId, path: &str, ) -> Result<String, ImportError>

Called when an importstr expression is evaluated.

source

fn import_bin( &mut self, program: &mut Program, from: SpanId, path: &str, ) -> Result<Vec<u8>, ImportError>

Called when an importbin expression is evaluated.

source

fn trace( &mut self, program: &mut Program, message: &str, stack: &[EvalStackTraceItem], )

Called when a call to std.trace is evaluated.

source

fn native_call( &mut self, program: &mut Program, name: &InternedStr, args: &[Value], ) -> Result<Value, NativeError>

Called when a function returned by std.native is called.

Native functions must be registered with Program::register_native_func.

Implementors§