Skip to content

Commit 74a11b0

Browse files
committed
Rework of the typed Signal API:
- `Class::signals()` now takes self by reference (`&self`) instead of `&mut self`, similar changes to the `connect_**` methods. This was introduced to avoid `clone()` boilerplate when a class wants to connect to a signal that belongs to one of their fields. - Replace trait `SignalReceiver` with direct usage of `FnMut($(Ps,)*)`. This fixes type inference issues with Rustc. - Standardized `connect` methods in the Signal API (both `TypedSignal` and `ConnectBuilder`), changes: - `connect`: (unchanged). - `connect_self`: now accepts both engine and user classes (by using the new trait `GodotDeref`). - `connect_obj`: renamed to `connect_other`, now accepts both engine and user classes (by using the new trait `GodotDeref`). - `ConnectBuilder::function`: renamed to `connect`. - `ConnectBuilder::method_mut`: split into `connect_self` and `connect_other`. - `ConnectBuilder::method_immut`: removed. - `ConnectBuilder::done`: removed, building is finalized upon calling one of the `connect_**` methods. - Removed type-state pattern on ConnectBuilder, and trimmed down generics.
1 parent aed6925 commit 74a11b0

File tree

11 files changed

+489
-505
lines changed

11 files changed

+489
-505
lines changed

godot-codegen/src/generator/signals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ fn make_with_signals_impl(
120120

121121
// During construction, C = Self.
122122
#[doc(hidden)]
123-
fn __signals_from_external(gd_mut: &mut Gd<Self>) -> Self::SignalCollection<'_, Self> {
123+
fn __signals_from_external(gd_ref: & Gd<Self>) -> Self::SignalCollection<'_, Self> {
124124
Self::SignalCollection {
125-
__internal_obj: Some(gd_mut.clone()),
125+
__internal_obj: Some(gd_ref.clone()),
126126
}
127127
}
128128
}

godot-core/src/obj/gd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ where
732732
///
733733
/// [`WithUserSignals::signals()`]: crate::obj::WithUserSignals::signals()
734734
#[cfg(since_api = "4.2")]
735-
pub fn signals(&mut self) -> T::SignalCollection<'_, T> {
735+
pub fn signals(&self) -> T::SignalCollection<'_, T> {
736736
T::__signals_from_external(self)
737737
}
738738
}

godot-core/src/obj/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ pub trait WithSignals: GodotClass + Inherits<crate::classes::Object> {
473473
///
474474
/// Takes by reference and not value, to retain lifetime chain.
475475
#[doc(hidden)]
476-
fn __signals_from_external(external: &mut Gd<Self>) -> Self::SignalCollection<'_, Self>;
476+
fn __signals_from_external(external: &Gd<Self>) -> Self::SignalCollection<'_, Self>;
477477
}
478478

479479
/// Implemented for user-defined classes with at least one `#[signal]` declaration.

0 commit comments

Comments
 (0)