Skip to main content

Callable

Trait Callable 

Source
pub trait Callable: Object {
    // Required method
    fn call(&self, cx: &mut Cx, args: Args) -> Result<Value>;

    // Provided methods
    fn browse_args_shape(&self, _cx: &mut Cx) -> Result<Option<ShapeRef>> { ... }
    fn browse_result_shape(&self, _cx: &mut Cx) -> Result<Option<ShapeRef>> { ... }
    fn call_exprs(&self, cx: &mut Cx, args: RawArgs) -> Result<Value> { ... }
}
Expand description

Runtime protocol for values that can be called.

Functions, constructors, macros that accept raw expressions, and host or guest function stubs all share this protocol. A callable is always a runtime object, so it also has a class, display form, reflection table, and optional protocol views through Object.

Required Methods§

Source

fn call(&self, cx: &mut Cx, args: Args) -> Result<Value>

Invoke the callable with already-evaluated, checked Args.

Provided Methods§

Source

fn browse_args_shape(&self, _cx: &mut Cx) -> Result<Option<ShapeRef>>

Optional shape describing the accepted argument list, for browsing.

Source

fn browse_result_shape(&self, _cx: &mut Cx) -> Result<Option<ShapeRef>>

Optional shape describing the call result, for browsing.

Source

fn call_exprs(&self, cx: &mut Cx, args: RawArgs) -> Result<Value>

Invoke the callable on raw, unevaluated argument expressions.

The default evaluates each expression in cx and forwards to Callable::call; macro-like callables override to inspect raw forms.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<T> Callable for T
where T: Shape,