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:

§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, R> TypedSignal<'_, C, R>
where C: WithBaseField, R: ParamTuple + Sync + Send,

pub fn to_fallible_future(&self) -> FallibleSignalFuture<R>

Creates a fallible future for this signal.

The future will resolve the next time the signal is emitted. See FallibleSignalFuture for details.

pub fn to_future(&self) -> SignalFuture<R>

Creates a future for this signal.

The future will resolve the next time the Signal is emitted, but might panic if the signal object is freed. See SignalFuture for details.

§

impl<'c, C, Ps> TypedSignal<'c, C, Ps>
where C: WithBaseField, Ps: ParamTuple,

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>,

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>,

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>,

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, ()>

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().

Trait Implementations§

§

impl<C, R> IntoFuture for &TypedSignal<'_, C, R>
where C: WithBaseField, R: ParamTuple + Sync + Send,

§

type Output = R

The output that the future will produce on completion.
§

type IntoFuture = SignalFuture<R>

Which kind of future are we turning this into?
§

fn into_future(self) -> <&TypedSignal<'_, C, R> as IntoFuture>::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<'c, C, Ps> Freeze for TypedSignal<'c, C, Ps>

§

impl<'c, C, Ps> RefUnwindSafe for TypedSignal<'c, C, Ps>

§

impl<'c, C, Ps> !Send for TypedSignal<'c, C, Ps>

§

impl<'c, C, Ps> !Sync for TypedSignal<'c, C, Ps>

§

impl<'c, C, Ps> Unpin for TypedSignal<'c, C, Ps>
where Ps: Unpin, <<C as Bounds>::Declarer as Declarer>::InstanceCache: Unpin,

§

impl<'c, C, Ps> !UnwindSafe for TypedSignal<'c, C, Ps>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.