godot::obj::cap

Trait WithSignals

pub trait WithSignals: WithBaseField {
    type SignalCollection<'a>;

    // Required method
    fn signals(&mut self) -> Self::SignalCollection<'_>;
}

Required Associated Types§

Required Methods§

fn signals(&mut self) -> Self::SignalCollection<'_>

Access user-defined signals of the current object self.

For classes that have at least one #[signal] defined, returns a collection of signal names. Each returned signal has a specialized API for connecting and emitting signals in a type-safe way. If you need to access signals from outside (given a Gd pointer), use Gd::signals() instead.

If you haven’t already, read the book chapter about signals for a walkthrough.

§Provided API

The returned collection provides a method for each signal, with the same name as the corresponding #[signal].
For example, if you have…

#[signal]
fn damage_taken(&mut self, amount: i32);

…then you can access the signal as self.signals().damage_taken(), which returns an object with the following API:

Method signatureDescription
connect(f: impl FnMut(i32))Connects global or associated function, or a closure.
connect_self(f: impl FnMut(&mut Self, i32))Connects a &mut self method or closure.
emit(amount: i32)Emits the signal with the given arguments.

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§