Trait Callbacks

Source
pub trait Callbacks<'p> {
    // Required methods
    fn import(
        &mut self,
        program: &mut Program<'p>,
        from: SpanId,
        path: &str,
    ) -> Result<Thunk<'p>, ImportError>;
    fn import_str(
        &mut self,
        program: &mut Program<'p>,
        from: SpanId,
        path: &str,
    ) -> Result<String, ImportError>;
    fn import_bin(
        &mut self,
        program: &mut Program<'p>,
        from: SpanId,
        path: &str,
    ) -> Result<Vec<u8>, ImportError>;
    fn trace(
        &mut self,
        program: &mut Program<'p>,
        message: &str,
        stack: &[EvalStackTraceItem],
    );
    fn native_call(
        &mut self,
        program: &mut Program<'p>,
        name: InternedStr<'p>,
        args: &[Value<'p>],
    ) -> Result<Value<'p>, 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<'p>, from: SpanId, path: &str, ) -> Result<Thunk<'p>, ImportError>

Called when an import expression is evaluated.

Source

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

Called when an importstr expression is evaluated.

Source

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

Called when an importbin expression is evaluated.

Source

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

Called when a call to std.trace is evaluated.

Source

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

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

Native functions must be registered with Program::register_native_func.

Implementors§