Skip to main content

WithUserRpcs

Trait WithUserRpcs 

Source
pub trait WithUserRpcs: WithBaseField + Inherits<Node> {
    type RpcCollection<'c>;

    // Required method
    fn rpcs(&mut self) -> Self::RpcCollection<'_>;
}
Expand description

Implemented for user-defined classes with at least one #[rpc] declaration.

Allows accessing type-safe RPCs from within the class, as self.rpcs(). This requires a Base<T> field and a Node-derived class. To access RPCs from outside (given a Gd pointer), use Gd::rpcs() instead.

Required Associated Types§

Source

type RpcCollection<'c>

The associated struct listing all RPCs of this class.

'c denotes the lifetime during which the class instance is borrowed and its RPCs can be called.

Required Methods§

Source

fn rpcs(&mut self) -> Self::RpcCollection<'_>

Access type-safe RPCs of the current object self.

For classes that have at least one #[rpc] defined, returns a collection with one method per RPC. If you need to access RPCs from outside (given a Gd pointer), use Gd::rpcs() instead.

§Provided API

The returned collection provides a method for each RPC, with the same name as the corresponding #[rpc].
For example, the following RPC:

#[rpc]
fn say_hello_to(&mut self, to: String) {
    godot_print!("hello, {to}");
}

can be called with:

my_node.rpcs().say_hello_to("world".to_string()).call();
my_node.rpcs().say_hello_to("world".to_string()).call_id(1); // call RPC on specific peer

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§