Trait WithUserSignals
pub trait WithUserSignals: WithSignals + WithBaseField {
// Required method
fn signals(&mut self) -> Self::SignalCollection<'_, Self>;
}Expand description
Implemented for user-defined classes with at least one #[signal] declaration.
Allows to access signals from within the class, as self.signals(). This requires a Base<T> field.
Required Methods§
fn signals(&mut self) -> Self::SignalCollection<'_, Self>
fn signals(&mut self) -> Self::SignalCollection<'_, Self>
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:
// Connects global or associated function, or a closure.
fn connect(f: impl FnMut(i32));
// Connects a &mut self method or closure on the emitter object.
fn connect_self(f: impl FnMut(&mut Self, i32));
// Connects a &mut self method or closure on another object.
fn connect_other<C>(f: impl FnMut(&mut C, i32));
// Emits the signal with the given arguments.
fn emit(amount: i32);See TypedSignal for more information.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".