Struct TypedSignal
pub struct TypedSignal<'c, C, Ps>where
C: GodotClass,{ /* private fields */ }
Expand description
Type-safe version of a Godot signal.
Short-lived type, only valid in the scope of its surrounding object type C
, for lifetime 'c
. The generic argument Ps
represents
the parameters of the signal, thus ensuring the type safety.
The WithSignals::signals()
collection returns multiple signals with distinct, code-generated types,
but they all implement Deref
and DerefMut
to TypedSignal
. This allows you to either use the concrete APIs of the generated types,
or the more generic ones of TypedSignal
.
§Connecting a signal to a receiver
Receiver functions are functions that are called when a signal is emitted. You can connect a signal in many different ways:
connect()
for global functions, associated functions or closures.connect_self()
for methods with&mut self
as the first parameter.connect_obj()
for methods with anyGd<T>
(notself
) as the first parameter.connect_builder()
for more complex setups.
§Emitting a signal
Code-generated signal types provide a method emit(...)
, which adopts the names and types of the #[signal]
parameter list.
In most cases, that’s the method you are looking for.
For generic use, you can also use emit_tuple()
, which does not provide parameter names.
§More information
See the Signals chapter in the book for a detailed introduction and examples.
Implementations§
§impl<'c, C, Ps> TypedSignal<'c, C, Ps>where
C: WithBaseField,
Ps: ParamTuple,
impl<'c, C, Ps> TypedSignal<'c, C, Ps>where
C: WithBaseField,
Ps: ParamTuple,
pub fn emit_tuple(&mut self, args: Ps)
pub fn emit_tuple(&mut self, args: Ps)
Emit the signal with the given parameters.
This is intended for generic use. Typically, you’ll want to use the more specific emit()
method of the code-generated signal
type, which also has named parameters.
pub fn connect<F>(&mut self, function: F)where
F: SignalReceiver<(), Ps>,
pub fn connect<F>(&mut self, function: F)where
F: SignalReceiver<(), Ps>,
Connect a non-member function (global function, associated function or closure).
Example usages:
sig.connect(Self::static_func);
sig.connect(global_func);
sig.connect(|arg| { /* closure */ });
To connect to a method of the own object self
, use connect_self()
.
If you need cross-thread signals or connect flags, use connect_builder()
.
pub fn connect_self<F>(&mut self, function: F)where
F: for<'c_rcv> SignalReceiver<&'c_rcv mut C, Ps>,
pub fn connect_self<F>(&mut self, function: F)where
F: for<'c_rcv> SignalReceiver<&'c_rcv mut C, Ps>,
Connect a method (member function) with &mut self
as the first parameter.
To connect to methods on other objects, use connect_obj()
.
If you need a &self
receiver, cross-thread signals or connect flags, use connect_builder()
.
pub fn connect_obj<F, OtherC>(&mut self, object: &Gd<OtherC>, function: F)where
OtherC: GodotClass<Declarer = DeclUser> + Bounds,
F: for<'c_rcv> SignalReceiver<&'c_rcv mut OtherC, Ps>,
pub fn connect_obj<F, OtherC>(&mut self, object: &Gd<OtherC>, function: F)where
OtherC: GodotClass<Declarer = DeclUser> + Bounds,
F: for<'c_rcv> SignalReceiver<&'c_rcv mut OtherC, Ps>,
Connect a method (member function) with any Gd<T>
(not self
) as the first parameter.
To connect to methods on the same object that declares the #[signal]
, use connect_self()
.
If you need cross-thread signals or connect flags, use connect_builder()
.
pub fn connect_builder(&mut self) -> ConnectBuilder<'_, 'c, C, (), Ps, ()>
pub fn connect_builder(&mut self) -> ConnectBuilder<'_, 'c, C, (), Ps, ()>
Fully customizable connection setup.
The returned builder provides several methods to configure how to connect the signal. It needs to be finalized with a call to
ConnectBuilder::done()
.