#[non_exhaustive]
pub enum CallableFunction {
    Pure {
        func: Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>,
        has_context: bool,
    },
    Method {
        func: Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>,
        has_context: bool,
    },
    Iterator {
        func: Shared<dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Result<Dynamic, Box<EvalAltResult>>>>>,
    },
    Plugin {
        func: Shared<dyn PluginFunction>,
    },
    Script {
        fn_def: Shared<ScriptFnDef>,
        environ: Option<Shared<EncapsulatedEnviron>>,
    },
}
Expand description

(internals) A type encapsulating a function callable by Rhai. Exported under the internals feature only.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Pure

Fields

§func: Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>

Shared function pointer.

§has_context: bool

Does the function take a NativeCallContext parameter?

A pure native Rust function with all arguments passed by value.

§

Method

Fields

§func: Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>

Shared function pointer.

§has_context: bool

Does the function take a NativeCallContext parameter?

A native Rust object method with the first argument passed by reference, and the rest passed by value.

§

Iterator

Fields

§func: Shared<dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Result<Dynamic, Box<EvalAltResult>>>>>

Shared function pointer.

An iterator function.

§

Plugin

Fields

§func: Shared<dyn PluginFunction>

Shared function pointer.

A plugin function,

§

Script

Fields

§fn_def: Shared<ScriptFnDef>

Shared reference to the ScriptFnDef function definition.

§environ: Option<Shared<EncapsulatedEnviron>>

Encapsulated environment, if any.

A script-defined function.

Implementations§

source§

impl CallableFunction

source

pub fn is_pure(&self) -> bool

Is this a pure native Rust function?

source

pub fn is_method(&self) -> bool

Is this a native Rust method function?

source

pub const fn is_iter(&self) -> bool

Is this an iterator function?

source

pub const fn is_script(&self) -> bool

Is this a script-defined function?

source

pub const fn is_plugin_fn(&self) -> bool

Is this a plugin function?

source

pub const fn is_native(&self) -> bool

Is this a native Rust function?

source

pub fn has_context(&self) -> bool

Is there a NativeCallContext parameter?

source

pub fn access(&self) -> FnAccess

Get the access mode.

source

pub fn get_native_fn( &self ) -> Option<&Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>>

Get a shared reference to a native Rust function.

source

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.

source

pub fn get_encapsulated_environ(&self) -> Option<&EncapsulatedEnviron>

Get a reference to the shared encapsulated environment of the function definition.

Not available under no_function or no_module.

source

pub fn get_iter_fn( &self ) -> Option<&dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Result<Dynamic, Box<EvalAltResult>>>>>

Get a reference to an iterator function.

source

pub fn get_plugin_fn(&self) -> Option<&Shared<dyn PluginFunction>>

Get a shared reference to a plugin function.

Trait Implementations§

source§

impl Clone for CallableFunction

source§

fn clone(&self) -> CallableFunction

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CallableFunction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for CallableFunction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Rc<ScriptFnDef>> for CallableFunction

source§

fn from(fn_def: Shared<ScriptFnDef>) -> Self

Converts to this type from the input type.
source§

impl From<Rc<dyn PluginFunction + 'static>> for CallableFunction

source§

fn from(func: Shared<dyn PluginFunction>) -> Self

Converts to this type from the input type.
source§

impl From<ScriptFnDef> for CallableFunction

source§

fn from(fn_def: ScriptFnDef) -> Self

Converts to this type from the input type.
source§

impl<T: PluginFunction + 'static + SendSync> From<T> for CallableFunction

source§

fn from(func: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.