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>

source

pub fn with_name(&mut self, name: &str) -> &mut Self

Set a pretty-print name for the type_of function.

source

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.

source

pub fn on_print( &mut self, on_print: impl Fn(&mut T) -> String + SendSync + 'static ) -> &mut Self

Pretty-print this custom type.

source

pub fn on_debug( &mut self, on_debug: impl Fn(&mut T) -> String + SendSync + 'static ) -> &mut Self

Debug-print this custom type.

source

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.

source

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>

source

pub fn is_iterable(&mut self) -> &mut Self

Register a type iterator. This is an advanced API.

source§

impl<T: Variant + Clone> TypeBuilder<'_, T>

source

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.

source

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.

source

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>

source

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.

source

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.

source

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>

source

pub fn with_result_fn<S, A: 'static, const N: usize, const X: bool, R, FUNC>( &mut self, name: S, method: FUNC ) -> &mut Self
where 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

Register a custom fallible function.

§Deprecated

This method is deprecated. Use with_fn instead.

This method will be removed in the next major version.

source

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

👎Deprecated since 1.9.1: use with_get instead

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.

source

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

👎Deprecated since 1.9.1: use with_set instead

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.

source

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

👎Deprecated since 1.9.1: use with_indexer_get instead

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.

source

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

👎Deprecated since 1.9.1: use with_indexer_set instead

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.

Auto Trait Implementations§

§

impl<'a, T> Freeze for TypeBuilder<'a, T>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.