Struct rhai::TypeBuilder
source · pub struct TypeBuilder<'a, T: Variant + Clone> { /* private fields */ }
Expand description
Builder to build the API of a custom type for use with an Engine
.
The type is automatically registered when this builder is dropped.
§Pretty-Print Name
By default the type is registered with Engine::register_type
(i.e. without a pretty-print name).
To define a pretty-print name, call with_name
,
to use Engine::register_type_with_name
instead.
Implementations§
source§impl<T: Variant + Clone> TypeBuilder<'_, T>
impl<T: Variant + Clone> TypeBuilder<'_, T>
sourcepub fn with_name(&mut self, name: &str) -> &mut Self
pub fn with_name(&mut self, name: &str) -> &mut Self
Set a pretty-print name for the type_of
function.
sourcepub fn with_comments(&mut self, comments: &[&str]) -> &mut Self
pub fn with_comments(&mut self, comments: &[&str]) -> &mut Self
Set a comments for the type.
TypeBuilder::with_name
must be called before this function, otherwise
the comments will not be registered.
Available with the metadata feature only.
sourcepub fn on_print(
&mut self,
on_print: impl Fn(&mut T) -> String + SendSync + 'static
) -> &mut Self
pub fn on_print( &mut self, on_print: impl Fn(&mut T) -> String + SendSync + 'static ) -> &mut Self
Pretty-print this custom type.
sourcepub fn on_debug(
&mut self,
on_debug: impl Fn(&mut T) -> String + SendSync + 'static
) -> &mut Self
pub fn on_debug( &mut self, on_debug: impl Fn(&mut T) -> String + SendSync + 'static ) -> &mut Self
Debug-print this custom type.
sourcepub fn with_fn<A: 'static, const N: usize, const X: bool, R: Variant + Clone, const F: bool>(
&mut self,
name: impl AsRef<str> + Into<Identifier>,
method: impl RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static
) -> &mut Self
pub fn with_fn<A: 'static, const N: usize, const X: bool, R: Variant + Clone, const F: bool>( &mut self, name: impl AsRef<str> + Into<Identifier>, method: impl RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static ) -> &mut Self
Register a custom method.
sourcepub fn and_comments(&mut self, comments: &[&str]) -> &mut Self
pub fn and_comments(&mut self, comments: &[&str]) -> &mut Self
(metadata) Add comments to the last registered function.
Available under the metadata
feature only.
source§impl<T> TypeBuilder<'_, T>
impl<T> TypeBuilder<'_, T>
sourcepub fn is_iterable(&mut self) -> &mut Self
pub fn is_iterable(&mut self) -> &mut Self
Register a type iterator. This is an advanced API.
source§impl<T: Variant + Clone> TypeBuilder<'_, T>
impl<T: Variant + Clone> TypeBuilder<'_, T>
sourcepub fn with_get<const X: bool, R: Variant + Clone, const F: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, F> + SendSync + 'static
) -> &mut Self
pub fn with_get<const X: bool, R: Variant + Clone, const F: bool>( &mut self, name: impl AsRef<str>, get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, F> + SendSync + 'static ) -> &mut Self
Register a getter function.
The function signature must start with &mut self
and not &self
.
Not available under no_object
.
sourcepub fn with_set<const X: bool, R: Variant + Clone, const F: bool>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), F> + SendSync + 'static
) -> &mut Self
pub fn with_set<const X: bool, R: Variant + Clone, const F: bool>( &mut self, name: impl AsRef<str>, set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), F> + SendSync + 'static ) -> &mut Self
Register a setter function.
Not available under no_object
.
sourcepub fn with_get_set<const X1: bool, const X2: bool, R: Variant + Clone, const F1: bool, const F2: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X1, R, F1> + SendSync + 'static,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X2, (), F2> + SendSync + 'static
) -> &mut Self
pub fn with_get_set<const X1: bool, const X2: bool, R: Variant + Clone, const F1: bool, const F2: bool>( &mut self, name: impl AsRef<str>, get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X1, R, F1> + SendSync + 'static, set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X2, (), F2> + SendSync + 'static ) -> &mut Self
Short-hand for registering both getter and setter functions.
All function signatures must start with &mut self
and not &self
.
Not available under no_object
.
source§impl<T: Variant + Clone> TypeBuilder<'_, T>
impl<T: Variant + Clone> TypeBuilder<'_, T>
sourcepub fn with_indexer_get<IDX: Variant + Clone, const X: bool, R: Variant + Clone, const F: bool>(
&mut self,
get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, F> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get<IDX: Variant + Clone, const X: bool, R: Variant + Clone, const F: bool>( &mut self, get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, F> + SendSync + 'static ) -> &mut Self
Register an index getter.
The function signature must start with &mut self
and not &self
.
Not available under both no_index
and no_object
.
sourcepub fn with_indexer_set<IDX: Variant + Clone, const X: bool, R: Variant + Clone, const F: bool>(
&mut self,
set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), F> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_set<IDX: Variant + Clone, const X: bool, R: Variant + Clone, const F: bool>( &mut self, set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), F> + SendSync + 'static ) -> &mut Self
Register an index setter.
Not available under both no_index
and no_object
.
sourcepub fn with_indexer_get_set<IDX: Variant + Clone, const X1: bool, const X2: bool, R: Variant + Clone, const F1: bool, const F2: bool>(
&mut self,
get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X1, R, F1> + SendSync + 'static,
set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X2, (), F2> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get_set<IDX: Variant + Clone, const X1: bool, const X2: bool, R: Variant + Clone, const F1: bool, const F2: bool>( &mut self, get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X1, R, F1> + SendSync + 'static, set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X2, (), F2> + SendSync + 'static ) -> &mut Self
Short-hand for registering both index getter and setter functions.
Not available under both no_index
and no_object
.
source§impl<T: Variant + Clone> TypeBuilder<'_, T>
impl<T: Variant + Clone> TypeBuilder<'_, T>
sourcepub fn with_result_fn<S, A: 'static, const N: usize, const X: bool, R, FUNC>(
&mut self,
name: S,
method: FUNC
) -> &mut Selfwhere
S: AsRef<str> + Into<Identifier>,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, true> + SendSync + 'static,
👎Deprecated since 1.9.1: use with_fn
instead
pub fn with_result_fn<S, A: 'static, const N: usize, const X: bool, R, FUNC>(
&mut self,
name: S,
method: FUNC
) -> &mut Selfwhere
S: AsRef<str> + Into<Identifier>,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, true> + SendSync + 'static,
with_fn
insteadsourcepub fn with_get_result<const X: bool, R: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use with_get
instead
pub fn with_get_result<const X: bool, R: Variant + Clone>( &mut self, name: impl AsRef<str>, get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, true> + SendSync + 'static ) -> &mut Self
with_get
insteadsourcepub fn with_set_result<const X: bool, R: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use with_set
instead
pub fn with_set_result<const X: bool, R: Variant + Clone>( &mut self, name: impl AsRef<str>, set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), true> + SendSync + 'static ) -> &mut Self
with_set
insteadsourcepub fn with_indexer_get_result<IDX: Variant + Clone, R: Variant + Clone, const X: bool>(
&mut self,
get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use with_indexer_get
instead
pub fn with_indexer_get_result<IDX: Variant + Clone, R: Variant + Clone, const X: bool>( &mut self, get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, true> + SendSync + 'static ) -> &mut Self
with_indexer_get
insteadRegister an fallible index getter.
The function signature must start with &mut self
and not &self
.
Not available under both no_index
and no_object
.
§Deprecated
This method is deprecated.
Use with_indexer_get
instead.
This method will be removed in the next major version.
sourcepub fn with_indexer_set_result<IDX: Variant + Clone, R: Variant + Clone, const X: bool>(
&mut self,
set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use with_indexer_set
instead
pub fn with_indexer_set_result<IDX: Variant + Clone, R: Variant + Clone, const X: bool>( &mut self, set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), true> + SendSync + 'static ) -> &mut Self
with_indexer_set
insteadRegister an fallible index setter.
Not available under both no_index
and no_object
.
§Deprecated
This method is deprecated.
Use with_indexer_set
instead.
This method will be removed in the next major version.