Enum rhai::plugin::CallableFunction
source · [−]#[non_exhaustive]
pub enum CallableFunction {
Pure(Shared<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>),
Method(Shared<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>),
Iterator(Shared<dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>>>),
Plugin(Shared<dyn PluginFunction>),
Script(Shared<ScriptFnDef>),
}
Expand description
A type encapsulating a function callable by Rhai.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Pure(Shared<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>)
A pure native Rust function with all arguments passed by value.
Method(Shared<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>)
A native Rust object method with the first argument passed by reference, and the rest passed by value.
Iterator(Shared<dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>>>)
An iterator function.
Plugin(Shared<dyn PluginFunction>)
A plugin function,
Script(Shared<ScriptFnDef>)
A script-defined function.
Implementations
sourceimpl CallableFunction
impl CallableFunction
sourcepub const fn is_plugin_fn(&self) -> bool
pub const fn is_plugin_fn(&self) -> bool
Is this a plugin function?
sourcepub fn get_native_fn(
&self
) -> Option<&Shared<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>>
pub fn get_native_fn(
&self
) -> Option<&Shared<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>>
Get a shared reference to a native Rust function.
sourcepub const fn get_script_fn_def(&self) -> Option<&Shared<ScriptFnDef>>
pub const fn get_script_fn_def(&self) -> Option<&Shared<ScriptFnDef>>
Get a shared reference to a script-defined function definition.
Not available under no_function
.
sourcepub fn get_iter_fn(
&self
) -> Option<&dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>>>
pub fn get_iter_fn(
&self
) -> Option<&dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>>>
Get a reference to an iterator function.
sourcepub fn get_plugin_fn(&self) -> Option<&Shared<dyn PluginFunction>>
pub fn get_plugin_fn(&self) -> Option<&Shared<dyn PluginFunction>>
Get a shared reference to a plugin function.
sourcepub fn from_pure(
func: Box<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>
) -> Self
pub fn from_pure(
func: Box<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>
) -> Self
Create a new CallableFunction::Pure
.
sourcepub fn from_method(
func: Box<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>
) -> Self
pub fn from_method(
func: Box<dyn Fn(NativeCallContext<'_>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>
) -> Self
Create a new CallableFunction::Method
.
sourcepub fn from_plugin(func: impl PluginFunction + 'static + SendSync) -> Self
pub fn from_plugin(func: impl PluginFunction + 'static + SendSync) -> Self
Create a new CallableFunction::Plugin
.
Trait Implementations
sourceimpl Clone for CallableFunction
impl Clone for CallableFunction
sourcefn clone(&self) -> CallableFunction
fn clone(&self) -> CallableFunction
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CallableFunction
impl Debug for CallableFunction
sourceimpl Display for CallableFunction
impl Display for CallableFunction
sourceimpl From<Rc<ScriptFnDef>> for CallableFunction
impl From<Rc<ScriptFnDef>> for CallableFunction
sourcefn from(_func: Shared<ScriptFnDef>) -> Self
fn from(_func: Shared<ScriptFnDef>) -> Self
Converts to this type from the input type.
sourceimpl From<Rc<dyn PluginFunction + 'static>> for CallableFunction
impl From<Rc<dyn PluginFunction + 'static>> for CallableFunction
sourcefn from(func: Shared<dyn PluginFunction>) -> Self
fn from(func: Shared<dyn PluginFunction>) -> Self
Converts to this type from the input type.
sourceimpl From<ScriptFnDef> for CallableFunction
impl From<ScriptFnDef> for CallableFunction
sourcefn from(_func: ScriptFnDef) -> Self
fn from(_func: ScriptFnDef) -> Self
Converts to this type from the input type.
sourceimpl<T: PluginFunction + 'static + SendSync> From<T> for CallableFunction
impl<T: PluginFunction + 'static + SendSync> From<T> for CallableFunction
Auto Trait Implementations
impl !RefUnwindSafe for CallableFunction
impl !Send for CallableFunction
impl !Sync for CallableFunction
impl Unpin for CallableFunction
impl !UnwindSafe for CallableFunction
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more