Trait RustCallable

pub trait RustCallable:
    'static
    + PartialEq
    + Hash
    + Display
    + Send
    + Sync {
    // Required method
    fn invoke(&mut self, args: &[&Variant]) -> Result<Variant, ()>;

    // Provided method
    fn is_valid(&self) -> bool { ... }
}
Expand description

Represents a custom callable object defined in Rust.

This trait has a single method, invoke, which is called upon invocation.

Since callables can be invoked from anywhere, they must be self-contained ('static) and thread-safe (Send + Sync). They also should implement Display for the Godot string representation. Furthermore, PartialEq and Hash are required for equality checks and usage as a key in a Dictionary.

Required Methods§

fn invoke(&mut self, args: &[&Variant]) -> Result<Variant, ()>

Invokes the callable with the given arguments as Variant references.

Return Ok(...) if the call succeeded, and Err(()) otherwise. Error handling is mostly needed in case argument number or types mismatch.

Provided Methods§

fn is_valid(&self) -> bool

Returns whether the callable is considered valid.

True by default.

If this Callable stores an object, this method should return whether that object is alive.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§