Struct rhai::TypeBuilder
source · [−]This type is NOT deprecated, but it is considered volatile and may change in the future.
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
sourceimpl<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
sourcepub fn with_name(&mut self, name: &'static str) -> &mut Self
pub fn with_name(&mut self, name: &'static str) -> &mut Self
Set a pretty-print name for the type_of
function.
sourcepub fn with_fn<N, A, F>(&mut self, name: N, method: F) -> &mut Self where
N: AsRef<str> + Into<Identifier>,
F: RegisterNativeFunction<A, ()>,
pub fn with_fn<N, A, F>(&mut self, name: N, method: F) -> &mut Self where
N: AsRef<str> + Into<Identifier>,
F: RegisterNativeFunction<A, ()>,
Register a custom function.
sourcepub fn with_result_fn<N, A, F, R>(&mut self, name: N, method: F) -> &mut Self where
N: AsRef<str> + Into<Identifier>,
F: RegisterNativeFunction<A, Result<R, Box<EvalAltResult>>>,
pub fn with_result_fn<N, A, F, R>(&mut self, name: N, method: F) -> &mut Self where
N: AsRef<str> + Into<Identifier>,
F: RegisterNativeFunction<A, Result<R, Box<EvalAltResult>>>,
Register a custom fallible function.
sourceimpl<'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.
sourceimpl<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
sourcepub fn with_get<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl Fn(&mut T) -> V + SendSync + 'static
) -> &mut Self
pub fn with_get<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl Fn(&mut T) -> V + 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_get_result<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl Fn(&mut T) -> Result<V, Box<EvalAltResult>> + SendSync + 'static
) -> &mut Self
pub fn with_get_result<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl Fn(&mut T) -> Result<V, Box<EvalAltResult>> + 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
.
sourcepub fn with_set<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
set_fn: impl Fn(&mut T, V) + SendSync + 'static
) -> &mut Self
pub fn with_set<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
set_fn: impl Fn(&mut T, V) + SendSync + 'static
) -> &mut Self
Register a setter function.
Not available under no_object
.
sourcepub fn with_set_result<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
set_fn: impl Fn(&mut T, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> &mut Self
pub fn with_set_result<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
set_fn: impl Fn(&mut T, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> &mut Self
Register a fallible setter function.
Not available under no_object
.
sourcepub fn with_get_set<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl Fn(&mut T) -> V + SendSync + 'static,
set_fn: impl Fn(&mut T, V) + SendSync + 'static
) -> &mut Self
pub fn with_get_set<V: Variant + Clone>(
&mut self,
name: impl AsRef<str>,
get_fn: impl Fn(&mut T) -> V + SendSync + 'static,
set_fn: impl Fn(&mut T, V) + 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
.
sourceimpl<'a, T: Variant + Clone> TypeBuilder<'a, T>
impl<'a, T: Variant + Clone> TypeBuilder<'a, T>
sourcepub fn with_indexer_get<X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> V + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get<X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> V + 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_get_result<X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> Result<V, Box<EvalAltResult>> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get_result<X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> Result<V, Box<EvalAltResult>> + 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
.
sourcepub fn with_indexer_set<X: Variant + Clone, V: Variant + Clone>(
&mut self,
set_fn: impl Fn(&mut T, X, V) + SendSync + 'static
) -> &mut Self
pub fn with_indexer_set<X: Variant + Clone, V: Variant + Clone>(
&mut self,
set_fn: impl Fn(&mut T, X, V) + SendSync + 'static
) -> &mut Self
Register an index setter.
Not available under both no_index
and no_object
.
sourcepub fn with_indexer_set_result<X: Variant + Clone, V: Variant + Clone>(
&mut self,
set_fn: impl Fn(&mut T, X, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> &mut Self
pub fn with_indexer_set_result<X: Variant + Clone, V: Variant + Clone>(
&mut self,
set_fn: impl Fn(&mut T, X, V) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> &mut Self
Register an fallible index setter.
Not available under both no_index
and no_object
.
sourcepub fn with_indexer_get_set<X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> V + SendSync + 'static,
set_fn: impl Fn(&mut T, X, V) + SendSync + 'static
) -> &mut Self
pub fn with_indexer_get_set<X: Variant + Clone, V: Variant + Clone>(
&mut self,
get_fn: impl Fn(&mut T, X) -> V + SendSync + 'static,
set_fn: impl Fn(&mut T, X, V) + SendSync + 'static
) -> &mut Self
Short-hand for registering both index getter and setter functions.
Not available under both no_index
and no_object
.
Trait Implementations
Auto Trait Implementations
impl<'a, T> !RefUnwindSafe for TypeBuilder<'a, T>
impl<'a, T> !Send for TypeBuilder<'a, T>
impl<'a, T> !Sync for TypeBuilder<'a, T>
impl<'a, T> Unpin for TypeBuilder<'a, T> where
T: Unpin,
impl<'a, T> !UnwindSafe for TypeBuilder<'a, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more