pub struct FuncRegistration { /* private fields */ }
Expand description

Type for fine-tuned module function registration.

Implementations§

source§

impl FuncRegistration

source

pub fn new(name: impl Into<SmartString<LazyCompact>>) -> FuncRegistration

Create a new FuncRegistration.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Internal.

  • Purity: The function is assumed to be pure unless it is a property setter or an index setter.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

let mut module = Module::new();

fn inc(x: i64) -> i64 { x + 1 }

let f = FuncRegistration::new("inc")
    .with_namespace(FnNamespace::Global)
    .set_into_module(&mut module, inc);

let hash = f.hash;

assert!(module.contains_fn(hash));
source

pub fn new_getter(prop: impl AsRef<str>) -> FuncRegistration

Create a new FuncRegistration for a property getter.

Not available under no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

source

pub fn new_setter(prop: impl AsRef<str>) -> FuncRegistration

Create a new FuncRegistration for a property setter.

Not available under no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be no-pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

source

pub fn new_index_getter() -> FuncRegistration

Create a new FuncRegistration for an index getter.

Not available under both no_index and no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

source

pub fn new_index_setter() -> FuncRegistration

Create a new FuncRegistration for an index setter.

Not available under both no_index and no_object.

§Defaults
  • Accessibility: The function namespace is FnNamespace::Global.

  • Purity: The function is assumed to be no-pure.

  • Volatility: The function is assumed to be non-volatile – i.e. it guarantees the same result for the same input(s).

  • Metadata: No metadata for the function is registered.

source

pub fn with_namespace(self, namespace: FnNamespace) -> FuncRegistration

Set the namespace of the function.

source

pub fn with_purity(self, pure: bool) -> FuncRegistration

Set whether the function is pure. A pure function has no side effects.

source

pub fn with_volatility(self, volatile: bool) -> FuncRegistration

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

source

pub fn register_into_engine<A, const N: usize, const X: bool, R, const F: bool, FUNC>( self, engine: &mut Engine, func: FUNC ) -> &FuncMetadata
where A: 'static, R: Variant + Clone, FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,

Register the function into the specified Engine.

source

pub fn set_into_module<A, const N: usize, const X: bool, R, const F: bool, FUNC>( self, module: &mut Module, func: FUNC ) -> &FuncMetadata
where A: 'static, R: Variant + Clone, FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,

Register the function into the specified Module.

source

pub fn set_into_module_raw( self, module: &mut Module, arg_types: impl AsRef<[TypeId]>, func: RhaiFunc ) -> &FuncMetadata

Register the function into the specified Module.

§WARNING - Low Level API

This function is very low level. It takes a list of TypeId’s indicating the actual types of the parameters.

§Panics

Panics if the type of the first parameter is Array, Map, String, ImmutableString, &str or INT and the function name indicates that it is an index getter or setter.

Indexers for arrays, object maps, strings and integers cannot be registered.

Trait Implementations§

source§

impl Clone for FuncRegistration

source§

fn clone(&self) -> FuncRegistration

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 FuncRegistration

source§

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

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

impl Hash for FuncRegistration

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for FuncRegistration

source§

fn eq(&self, other: &FuncRegistration) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for FuncRegistration

source§

impl StructuralPartialEq for FuncRegistration

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
§

impl<T> CallHasher for T
where T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, 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> EventKey for T
where T: Hash + PartialEq + Eq + Send + Sync,