pub trait Callable {
// Required method
fn metadata(&self) -> Rc<CallableMetadata>;
// Provided methods
fn exec(&self, _scope: Scope<'_>) -> CallResult<()> { ... }
fn async_exec<'life0, 'life1, 'async_trait>(
&'life0 self,
_scope: Scope<'life1>,
) -> Pin<Box<dyn Future<Output = CallResult<()>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
A trait to define a callable that is executed by a Machine.
The callable themselves are immutable but they can reference mutable state. Given that
EndBASIC is not threaded, it is sufficient for those references to be behind a RefCell
and/or an Rc.
Idiomatically, these objects need to provide a new() method that returns an Rc<Callable>, as
that’s the type used throughout the execution engine.
Required Methods§
Sourcefn metadata(&self) -> Rc<CallableMetadata>
fn metadata(&self) -> Rc<CallableMetadata>
Returns the metadata for this function.
The return value takes the form of a reference to force the callable to store the metadata as a struct field so that calls to this function are guaranteed to be cheap.
Provided Methods§
Sourcefn exec(&self, _scope: Scope<'_>) -> CallResult<()>
fn exec(&self, _scope: Scope<'_>) -> CallResult<()>
Executes the callable if it is synchronous.
Sourcefn async_exec<'life0, 'life1, 'async_trait>(
&'life0 self,
_scope: Scope<'life1>,
) -> Pin<Box<dyn Future<Output = CallResult<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn async_exec<'life0, 'life1, 'async_trait>(
&'life0 self,
_scope: Scope<'life1>,
) -> Pin<Box<dyn Future<Output = CallResult<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the callable if it is asynchronous.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".