Enum rhai::RhaiFunc

source ·
#[non_exhaustive]
pub enum RhaiFunc { Pure { func: Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>, has_context: bool, is_pure: bool, is_volatile: bool, }, Method { func: Shared<dyn Fn(Option<NativeCallContext<'_>>, &mut [&'_ mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>>, has_context: bool, is_pure: bool, is_volatile: bool, }, Iterator { func: Shared<dyn Fn(Dynamic) -> Box<dyn Iterator<Item = Result<Dynamic, Box<EvalAltResult>>>>>, }, Plugin { func: Shared<dyn PluginFunc>, }, Script { fn_def: Shared<ScriptFuncDef>, 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

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

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?

§is_pure: bool

This is a dummy field and is not used.

§is_volatile: bool

Is this function volatile?

A volatile function does not guarantee the same result for the same input(s).

§

Method

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

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?

§is_pure: bool

Allow operating on constants?

§is_volatile: bool

Is this function volatile?

A volatile function does not guarantee the same result for the same input(s).

§

Iterator

An iterator function.

Fields

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

Shared function pointer.

§

Plugin

A plugin function,

Fields

§func: Shared<dyn PluginFunc>

Shared function pointer.

§

Script

A script-defined function.

Fields

§fn_def: Shared<ScriptFuncDef>

Shared reference to the ScriptFuncDef function definition.

§environ: Option<Shared<EncapsulatedEnviron>>

Encapsulated environment, if any.

Implementations§

source§

impl RhaiFunc

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 is_volatile(&self) -> bool

Is this function volatile?

A volatile function does not guarantee the same result for the same input(s).

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<ScriptFuncDef>>

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 PluginFunc>>

Get a shared reference to a plugin function.

Trait Implementations§

source§

impl Clone for RhaiFunc

source§

fn clone(&self) -> RhaiFunc

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 RhaiFunc

source§

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

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

impl Display for RhaiFunc

source§

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

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

impl From<Rc<ScriptFuncDef>> for RhaiFunc

source§

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

Converts to this type from the input type.
source§

impl From<Rc<dyn PluginFunc>> for RhaiFunc

source§

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

Converts to this type from the input type.
source§

impl From<ScriptFuncDef> for RhaiFunc

source§

fn from(fn_def: ScriptFuncDef) -> Self

Converts to this type from the input type.
source§

impl<T: PluginFunc + 'static + SendSync> From<T> for RhaiFunc

source§

fn from(func: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where 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 T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T> Variant for T
where T: Any + Clone + SendSync,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert this Variant trait object to &dyn Any.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert this Variant trait object to &mut dyn Any.
source§

fn as_boxed_any(self: Box<T>) -> Box<dyn Any>

Convert this Variant trait object to Box<dyn Any>.
source§

fn type_name(&self) -> &'static str

Get the name of this type.
source§

fn clone_object(&self) -> Box<dyn Variant>

Clone this Variant trait object.