Struct TypeBuilder
pub struct TypeBuilder<'a, T>where
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§
§impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
pub fn with_name(&mut self, name: &str) -> &mut TypeBuilder<'_, T>
pub fn with_name(&mut self, name: &str) -> &mut TypeBuilder<'_, T>
Set a pretty-print name for the type_of
function.
pub fn on_print(
&mut self,
on_print: impl Fn(&mut T) -> String + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>
pub fn on_print( &mut self, on_print: impl Fn(&mut T) -> String + SendSync + 'static, ) -> &mut TypeBuilder<'_, T>
Pretty-print this custom type.
pub fn on_debug(
&mut self,
on_debug: impl Fn(&mut T) -> String + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>
pub fn on_debug( &mut self, on_debug: impl Fn(&mut T) -> String + SendSync + 'static, ) -> &mut TypeBuilder<'_, T>
Debug-print this custom type.
pub fn with_fn<A, const N: usize, const X: bool, R, const F: bool>(
&mut self,
name: impl AsRef<str> + Into<SmartString<LazyCompact>>,
method: impl RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
A: 'static,
R: Variant + Clone,
pub fn with_fn<A, const N: usize, const X: bool, R, const F: bool>(
&mut self,
name: impl AsRef<str> + Into<SmartString<LazyCompact>>,
method: impl RhaiNativeFunc<A, N, X, R, F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
A: 'static,
R: Variant + Clone,
Register a custom method.
§impl<T> TypeBuilder<'_, T>
impl<T> TypeBuilder<'_, T>
pub fn is_iterable(&mut self) -> &mut TypeBuilder<'_, T>
pub fn is_iterable(&mut self) -> &mut TypeBuilder<'_, T>
Register a type iterator. This is an advanced API.
§impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
pub fn with_get<const X: bool, R, const F: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
pub fn with_get<const X: bool, R, const F: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
Register a getter function.
The function signature must start with &mut self
and not &self
.
Not available under no_object
.
pub fn with_set<const X: bool, R, const F: bool>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
pub fn with_set<const X: bool, R, const F: bool>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
Register a setter function.
Not available under no_object
.
pub fn with_get_set<const X1: bool, const X2: bool, R, 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 TypeBuilder<'_, T>where
R: Variant + Clone,
pub fn with_get_set<const X1: bool, const X2: bool, R, 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 TypeBuilder<'_, T>where
R: Variant + Clone,
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
.
§impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
pub fn with_indexer_get<IDX, const X: bool, R, const F: bool>(
&mut self,
get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>
pub fn with_indexer_get<IDX, const X: bool, R, const F: bool>( &mut self, get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, F> + SendSync + 'static, ) -> &mut TypeBuilder<'_, T>
Register an index getter.
The function signature must start with &mut self
and not &self
.
Not available under both no_index
and no_object
.
pub fn with_indexer_set<IDX, const X: bool, R, const F: bool>(
&mut self,
set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), F> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>
pub fn with_indexer_set<IDX, const X: bool, R, const F: bool>( &mut self, set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), F> + SendSync + 'static, ) -> &mut TypeBuilder<'_, T>
Register an index setter.
Not available under both no_index
and no_object
.
pub fn with_indexer_get_set<IDX, const X1: bool, const X2: bool, R, 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 TypeBuilder<'_, T>
pub fn with_indexer_get_set<IDX, const X1: bool, const X2: bool, R, 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 TypeBuilder<'_, T>
Short-hand for registering both index getter and setter functions.
Not available under both no_index
and no_object
.
§impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
impl<T> TypeBuilder<'_, T>where
T: Variant + Clone,
pub fn with_result_fn<S, A, const N: usize, const X: bool, R, FUNC>(
&mut self,
name: S,
method: FUNC,
) -> &mut TypeBuilder<'_, T>where
A: 'static,
S: AsRef<str> + Into<SmartString<LazyCompact>>,
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, const N: usize, const X: bool, R, FUNC>(
&mut self,
name: S,
method: FUNC,
) -> &mut TypeBuilder<'_, T>where
A: 'static,
S: AsRef<str> + Into<SmartString<LazyCompact>>,
R: Variant + Clone,
FUNC: RhaiNativeFunc<A, N, X, R, true> + SendSync + 'static,
with_fn
insteadpub fn with_get_result<const X: bool, R>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, true> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
👎Deprecated since 1.9.1: use with_get
instead
pub fn with_get_result<const X: bool, R>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RhaiNativeFunc<(Mut<T>,), 1, X, R, true> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
with_get
insteadpub fn with_set_result<const X: bool, R>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), true> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
👎Deprecated since 1.9.1: use with_set
instead
pub fn with_set_result<const X: bool, R>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RhaiNativeFunc<(Mut<T>, R), 2, X, (), true> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>where
R: Variant + Clone,
with_set
insteadpub fn with_indexer_get_result<IDX, R, const X: bool>(
&mut self,
get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, true> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>
👎Deprecated since 1.9.1: use with_indexer_get
instead
pub fn with_indexer_get_result<IDX, R, const X: bool>( &mut self, get_fn: impl RhaiNativeFunc<(Mut<T>, IDX), 2, X, R, true> + SendSync + 'static, ) -> &mut TypeBuilder<'_, T>
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.
pub fn with_indexer_set_result<IDX, R, const X: bool>(
&mut self,
set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), true> + SendSync + 'static,
) -> &mut TypeBuilder<'_, T>
👎Deprecated since 1.9.1: use with_indexer_set
instead
pub fn with_indexer_set_result<IDX, R, const X: bool>( &mut self, set_fn: impl RhaiNativeFunc<(Mut<T>, IDX, R), 3, X, (), true> + SendSync + 'static, ) -> &mut TypeBuilder<'_, T>
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.