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<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
source§impl<'a, T> TypeBuilder<'a, T>where
T: Variant + Clone + IntoIterator,
<T as IntoIterator>::Item: Variant + Clone,
impl<'a, T> TypeBuilder<'a, T>where T: Variant + Clone + IntoIterator, <T as IntoIterator>::Item: Variant + Clone,
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<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
sourcepub fn with_get<const C: bool, V: Variant + Clone, const L: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RegisterNativeFunction<(Mut<T>,), 1, C, V, L> + SendSync + 'static
) -> &mut Self
pub fn with_get<const C: bool, V: Variant + Clone, const L: bool>( &mut self, name: impl AsRef<str>, get_fn: impl RegisterNativeFunction<(Mut<T>,), 1, C, V, L> + 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 C: bool, V: Variant + Clone, const L: bool>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RegisterNativeFunction<(Mut<T>, V), 2, C, (), L> + SendSync + 'static
) -> &mut Self
pub fn with_set<const C: bool, V: Variant + Clone, const L: bool>( &mut self, name: impl AsRef<str>, set_fn: impl RegisterNativeFunction<(Mut<T>, V), 2, C, (), L> + SendSync + 'static ) -> &mut Self
Register a setter function.
Not available under no_object
.
sourcepub fn with_get_set<const C1: bool, const C2: bool, V: Variant + Clone, const L1: bool, const L2: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RegisterNativeFunction<(Mut<T>,), 1, C1, V, L1> + SendSync + 'static,
set_fn: impl RegisterNativeFunction<(Mut<T>, V), 2, C2, (), L2> + SendSync + 'static
) -> &mut Self
pub fn with_get_set<const C1: bool, const C2: bool, V: Variant + Clone, const L1: bool, const L2: bool>( &mut self, name: impl AsRef<str>, get_fn: impl RegisterNativeFunction<(Mut<T>,), 1, C1, V, L1> + SendSync + 'static, set_fn: impl RegisterNativeFunction<(Mut<T>, V), 2, C2, (), L2> + 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<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
sourcepub fn with_indexer_get<X: Variant + Clone, const C: bool, V: Variant + Clone, const L: bool>(
&mut self,
get_fn: impl RegisterNativeFunction<(Mut<T>, X), 2, C, V, L> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get<X: Variant + Clone, const C: bool, V: Variant + Clone, const L: bool>( &mut self, get_fn: impl RegisterNativeFunction<(Mut<T>, X), 2, C, V, L> + 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<X: Variant + Clone, const C: bool, V: Variant + Clone, const L: bool>(
&mut self,
set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), 3, C, (), L> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_set<X: Variant + Clone, const C: bool, V: Variant + Clone, const L: bool>( &mut self, set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), 3, C, (), L> + SendSync + 'static ) -> &mut Self
Register an index setter.
Not available under both no_index
and no_object
.
sourcepub fn with_indexer_get_set<X: Variant + Clone, const C1: bool, const C2: bool, V: Variant + Clone, const L1: bool, const L2: bool>(
&mut self,
get_fn: impl RegisterNativeFunction<(Mut<T>, X), 2, C1, V, L1> + SendSync + 'static,
set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), 3, C2, (), L2> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get_set<X: Variant + Clone, const C1: bool, const C2: bool, V: Variant + Clone, const L1: bool, const L2: bool>( &mut self, get_fn: impl RegisterNativeFunction<(Mut<T>, X), 2, C1, V, L1> + SendSync + 'static, set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), 3, C2, (), L2> + 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<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
sourcepub fn with_result_fn<S, A: 'static, const N: usize, const C: bool, R, F>(
&mut self,
name: S,
method: F
) -> &mut Selfwhere
S: AsRef<str> + Into<Identifier>,
R: Variant + Clone,
F: RegisterNativeFunction<A, N, C, R, true>,
👎Deprecated since 1.9.1: use <code>with_fn</code> instead
pub fn with_result_fn<S, A: 'static, const N: usize, const C: bool, R, F>( &mut self, name: S, method: F ) -> &mut Selfwhere S: AsRef<str> + Into<Identifier>, R: Variant + Clone, F: RegisterNativeFunction<A, N, C, R, true>,
Register a custom fallible function.
Deprecated
This method is deprecated. Use with_fn
instead.
This method will be removed in the next major version.
sourcepub fn with_get_result<V: Variant + Clone, const C: bool>(
&mut self,
name: impl AsRef<str>,
get_fn: impl RegisterNativeFunction<(Mut<T>,), 1, C, V, true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use <code>with_get</code> instead
pub fn with_get_result<V: Variant + Clone, const C: bool>( &mut self, name: impl AsRef<str>, get_fn: impl RegisterNativeFunction<(Mut<T>,), 1, C, V, true> + SendSync + 'static ) -> &mut Self
Register a fallible getter function.
The function signature must start with &mut self
and not &self
.
Not available under no_object
.
Deprecated
This method is deprecated. Use with_get
instead.
This method will be removed in the next major version.
sourcepub fn with_set_result<V: Variant + Clone, const C: bool>(
&mut self,
name: impl AsRef<str>,
set_fn: impl RegisterNativeFunction<(Mut<T>, V), 2, C, (), true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use <code>with_set</code> instead
pub fn with_set_result<V: Variant + Clone, const C: bool>( &mut self, name: impl AsRef<str>, set_fn: impl RegisterNativeFunction<(Mut<T>, V), 2, C, (), true> + SendSync + 'static ) -> &mut Self
Register a fallible setter function.
Not available under no_object
.
Deprecated
This method is deprecated. Use with_set
instead.
This method will be removed in the next major version.
sourcepub fn with_indexer_get_result<X: Variant + Clone, V: Variant + Clone, const C: bool>(
&mut self,
get_fn: impl RegisterNativeFunction<(Mut<T>, X), 2, C, V, true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use <code>with_indexer_get</code> instead
pub fn with_indexer_get_result<X: Variant + Clone, V: Variant + Clone, const C: bool>( &mut self, get_fn: impl RegisterNativeFunction<(Mut<T>, X), 2, C, V, true> + SendSync + 'static ) -> &mut Self
Register 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<X: Variant + Clone, V: Variant + Clone, const C: bool>(
&mut self,
set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), 3, C, (), true> + SendSync + 'static
) -> &mut Self
👎Deprecated since 1.9.1: use <code>with_indexer_set</code> instead
pub fn with_indexer_set_result<X: Variant + Clone, V: Variant + Clone, const C: bool>( &mut self, set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), 3, C, (), true> + SendSync + 'static ) -> &mut Self
Register 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.