Struct rhai::FuncRegistration
source · pub struct FuncRegistration { /* private fields */ }
Expand description
Type for fine-tuned module function registration.
Implementations§
source§impl FuncRegistration
impl FuncRegistration
sourcepub fn new(name: impl Into<Identifier>) -> Self
pub fn new(name: impl Into<Identifier>) -> Self
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));
sourcepub fn new_getter(prop: impl AsRef<str>) -> Self
pub fn new_getter(prop: impl AsRef<str>) -> Self
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.
sourcepub fn new_setter(prop: impl AsRef<str>) -> Self
pub fn new_setter(prop: impl AsRef<str>) -> Self
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.
sourcepub fn new_index_getter() -> Self
pub fn new_index_getter() -> Self
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.
sourcepub fn new_index_setter() -> Self
pub fn new_index_setter() -> Self
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.
sourcepub fn with_namespace(self, namespace: FnNamespace) -> Self
pub fn with_namespace(self, namespace: FnNamespace) -> Self
Set the namespace of the function.
sourcepub fn with_purity(self, pure: bool) -> Self
pub fn with_purity(self, pure: bool) -> Self
Set whether the function is pure. A pure function has no side effects.
sourcepub fn with_volatility(self, volatile: bool) -> Self
pub fn with_volatility(self, volatile: bool) -> Self
Set whether the function is volatile. A volatile function does not guarantee the same result for the same input(s).
sourcepub fn with_params_info<S: AsRef<str>>(
self,
params: impl IntoIterator<Item = S>
) -> Self
pub fn with_params_info<S: AsRef<str>>( self, params: impl IntoIterator<Item = S> ) -> Self
(metadata) Set the function’s parameter names and/or types.
Exported under the metadata
feature only.
The input is a list of strings, each of which is either a parameter name or a parameter name/type pair.
The last string should be the type of the return value.
§Parameter Examples
"foo: &str"
<- parameter name = foo
, type = &str
"bar"
<- parameter name = bar
, type unknown
"_: i64"
<- parameter name unknown, type = i64
"MyType"
<- parameter name unknown, type = MyType
sourcepub fn with_comments<S: AsRef<str>>(
self,
comments: impl IntoIterator<Item = S>
) -> Self
pub fn with_comments<S: AsRef<str>>( self, comments: impl IntoIterator<Item = S> ) -> Self
(metadata) Set the function’s doc-comments.
Exported under the metadata
feature only.
The input is a list of strings, each of which is either a block of single-line doc-comments or a single block doc-comment.
§Comments
Single-line doc-comments typically start with ///
and should be merged, with line-breaks,
into a single string without a final termination line-break.
Block doc-comments typically start with /**
and end with */
and should be kept in a
separate string.
Leading white-spaces should be stripped, and each string should always start with the
corresponding doc-comment leader: ///
or /**
.
Each line in non-block doc-comments should start with ///
.
sourcepub fn register_into_engine<A: 'static, const N: usize, const X: bool, R, const F: bool, FUNC>(
self,
engine: &mut Engine,
func: FUNC
) -> &FuncMetadata
pub fn register_into_engine<A: 'static, const N: usize, const X: bool, R, const F: bool, FUNC>( self, engine: &mut Engine, func: FUNC ) -> &FuncMetadata
Register the function into the specified Engine
.
sourcepub fn set_into_module<A: 'static, const N: usize, const X: bool, R, const F: bool, FUNC>(
self,
module: &mut Module,
func: FUNC
) -> &FuncMetadata
pub fn set_into_module<A: 'static, const N: usize, const X: bool, R, const F: bool, FUNC>( self, module: &mut Module, func: FUNC ) -> &FuncMetadata
Register the function into the specified Module
.
sourcepub 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§
source§impl Clone for FuncRegistration
impl Clone for FuncRegistration
source§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 moresource§impl Debug for FuncRegistration
impl Debug for FuncRegistration
source§impl Hash for FuncRegistration
impl Hash for FuncRegistration
source§impl PartialEq for FuncRegistration
impl PartialEq for FuncRegistration
source§fn eq(&self, other: &FuncRegistration) -> bool
fn eq(&self, other: &FuncRegistration) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for FuncRegistration
impl StructuralPartialEq for FuncRegistration
Auto Trait Implementations§
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> Variant for T
impl<T> Variant for T
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Variant
trait object to &mut dyn Any
.source§fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Variant
trait object to Box<dyn Any>
.