Struct FuncRegistration
pub struct FuncRegistration { /* private fields */ }
Expand description
Type for fine-tuned module function registration.
Implementations§
§impl FuncRegistration
impl FuncRegistration
pub fn new(name: impl Into<SmartString<LazyCompact>>) -> FuncRegistration
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")
.in_global_namespace()
.set_into_module(&mut module, inc);
let hash = f.hash;
assert!(module.contains_fn(hash));
pub fn new_getter(prop: impl AsRef<str>) -> FuncRegistration
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.
pub fn new_setter(prop: impl AsRef<str>) -> FuncRegistration
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.
pub fn new_index_getter() -> FuncRegistration
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.
pub fn new_index_setter() -> FuncRegistration
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.
pub const fn with_namespace(self, namespace: FnNamespace) -> FuncRegistration
pub const fn with_namespace(self, namespace: FnNamespace) -> FuncRegistration
Set the namespace of the function.
pub const fn in_global_namespace(self) -> FuncRegistration
pub const fn in_global_namespace(self) -> FuncRegistration
Set the function to the global namespace.
pub const fn in_internal_namespace(self) -> FuncRegistration
pub const fn in_internal_namespace(self) -> FuncRegistration
Set the function to the internal namespace.
pub const fn with_purity(self, pure: bool) -> FuncRegistration
pub const fn with_purity(self, pure: bool) -> FuncRegistration
Set whether the function is pure. A pure function has no side effects.
pub const fn with_volatility(self, volatile: bool) -> FuncRegistration
pub const 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).
pub fn register_into_engine<A, const N: usize, const X: bool, R, const F: bool, FUNC>(
self,
engine: &mut Engine,
func: FUNC,
) -> &FuncMetadatawhere
A: 'static,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,
pub fn register_into_engine<A, const N: usize, const X: bool, R, const F: bool, FUNC>(
self,
engine: &mut Engine,
func: FUNC,
) -> &FuncMetadatawhere
A: 'static,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,
Register the function into the specified Engine
.
pub fn set_into_module<A, const N: usize, const X: bool, R, const F: bool, FUNC>(
self,
module: &mut Module,
func: FUNC,
) -> &FuncMetadatawhere
A: 'static,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,
pub fn set_into_module<A, const N: usize, const X: bool, R, const F: bool, FUNC>(
self,
module: &mut Module,
func: FUNC,
) -> &FuncMetadatawhere
A: 'static,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,
Register the function into the specified Module
.
pub fn set_into_module_raw(
self,
module: &mut Module,
arg_types: impl AsRef<[TypeId]>,
func: RhaiFunc,
) -> &FuncMetadata
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§
§impl Clone for FuncRegistration
impl Clone for FuncRegistration
§fn clone(&self) -> FuncRegistration
fn clone(&self) -> FuncRegistration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for FuncRegistration
impl Debug for FuncRegistration
§impl Hash for FuncRegistration
impl Hash for FuncRegistration
§impl PartialEq for FuncRegistration
impl PartialEq for FuncRegistration
impl Eq for FuncRegistration
impl StructuralPartialEq for FuncRegistration
Auto Trait Implementations§
impl Freeze for FuncRegistration
impl RefUnwindSafe for FuncRegistration
impl Send for FuncRegistration
impl Sync for FuncRegistration
impl Unpin for FuncRegistration
impl UnwindSafe for FuncRegistration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.