@@ -16,17 +16,9 @@ use std::fmt::Debug;
16
16
17
17
/// Builder for customizing signal connections.
18
18
///
19
- /// Allows a high degree of customization for connecting signals , while maintaining complete type safety.
19
+ /// Allows a high degree of customization for connecting [`TypedSignal`] , while maintaining complete type safety.
20
20
///
21
- /// <div class="warning">
22
- /// <strong>Warning:</strong>
23
- /// Exact type parameters are subject to change and not part of the public API. We could annotate <code>#[doc(hidden)]</code>, but it would make
24
- /// things harder to understand. Thus, try not to name the <code>ConnectBuilder</code> type in your code; most connection setup doesn't need it.
25
- /// </div>
26
- // If naming the type becomes a requirement, there may be some options:
27
- // - Use a type alias in the module or TypedSignal, exposing only public parameters. This would work for constructor, but not all transformations.
28
- // - Pack multiple types together into "type lists", i.e. custom structs carrying the type state. For a user, this would appear as one type,
29
- // - which could also be #[doc(hidden)]. However, this may make the trait resolution more complex and worsen error messages, so not done now.
21
+ /// See the [Signals](https://godot-rust.github.io/book/register/signals.html) chapter in the book for a general introduction and examples.
30
22
///
31
23
/// # Customization
32
24
/// Customizing your signal connection must be done **before** providing the function being connected
@@ -39,13 +31,36 @@ use std::fmt::Debug;
39
31
/// - [`flags()`][Self::flags]: Provide one or multiple [`ConnectFlags`][crate::classes::object::ConnectFlags], possibly combined with bitwise OR.
40
32
///
41
33
/// # Finalizing
42
- /// After customizing your builder, you can register the connection by using one of the following methods:
43
- /// - [`connect()`][Self::connect]: Connect a global/associated function or a closure.
44
- /// - [`connect_self()`][Self::connect_self]: Connect a method or closure that runs on the signal emitter.
45
- /// - [`connect_other()`][Self::connect_other]: Connect a method or closure that runs on a separate object.
46
- /// - [`connect_sync()`](#method.connect_sync): Connect a global/associated function or closure that should be callable across threads. \
47
- /// Allows signal to be emitted from other threads. \
48
- /// Requires `Send` + `Sync` bounds on the provided function/method, and is only available for the `experimental-threads` Cargo feature.
34
+ /// After customizing your builder, you can register the connection with various `connect_*` functions.
35
+ ///
36
+ /// To connect to **methods** (member functions) with a signal object, you have the following combinations:
37
+ ///
38
+ /// | Signal object | 1st parameter `&mut C` | 1st parameter `&mut Gd<C>` |
39
+ /// |---------------|------------------------------------------------|----------------------------------------------|
40
+ /// | `self` | [`connect_self_mut`][Self::connect_self_mut] | [`connect_self_gd`][Self::connect_self_gd] |
41
+ /// | other object | [`connect_other_mut`][Self::connect_other_mut] | [`connect_other_gd`][Self::connect_other_gd] |
42
+ ///
43
+ /// <br>
44
+ ///
45
+ /// For **global functions, associated functions and closures**, you can use the following APIs:
46
+ /// - [`connect()`][Self::connect]: Connect any function running on the same thread as the signal emitter.
47
+ /// - [`connect_sync()`](#method.connect_sync): Connect a global/associated function or closure that should be callable across threads.
48
+ /// Allows signals to be emitted from other threads.
49
+ /// - Requires `Send` + `Sync` bounds on the provided function.
50
+ /// - Is only available for the Cargo feature `experimental-threads`.
51
+ ///
52
+ /// # Implementation and documentation notes
53
+ /// See [`TypedSignal` docs](struct.TypedSignal.html#implementation-and-documentation-notes) for a background on the `connect_*` API design.
54
+ ///
55
+ /// <div class="warning">
56
+ /// <strong>Warning:</strong>
57
+ /// Exact type parameters are subject to change and not part of the public API. Since it's a type-state API, new states might require new
58
+ /// type parameters. Thus, try not to name the <code>ConnectBuilder</code> type in your code; most connection setup doesn't need it.
59
+ /// </div>
60
+ // If naming the type becomes a requirement, there may be some options:
61
+ // - Use a type alias in the module or TypedSignal, exposing only public parameters. This would work for constructor, but not all transformations.
62
+ // - Pack multiple types together into "type lists", i.e. custom structs carrying the type state. For a user, this would appear as one type,
63
+ // - which could also be #[doc(hidden)]. However, this may make the trait resolution more complex and worsen error messages, so not done now.
49
64
#[ must_use]
50
65
pub struct ConnectBuilder < ' ts , ' c , C : WithSignals , Ps > {
51
66
parent_sig : & ' ts TypedSignal < ' c , C , Ps > ,
@@ -120,10 +135,8 @@ where
120
135
}
121
136
122
137
macro_rules! impl_builder_connect {
123
- ( $( $args: ident : $Ps: ident ) ,* ) => {
124
- // --------------------------------------------------------------------------------------------------------------------------------------
125
- // SignalReceiver
126
-
138
+ ( $( #[ $attr: meta] ) ? $( $args: ident : $Ps: ident ) ,* ) => {
139
+ $( #[ $attr] ) ?
127
140
impl <C : WithSignals , $( $Ps: Debug + FromGodot + ' static ) ,* >
128
141
ConnectBuilder <' _, ' _, C , ( $( $Ps, ) * ) > {
129
142
/// Connect a non-member function (global function, associated function or closure).
@@ -135,7 +148,11 @@ macro_rules! impl_builder_connect {
135
148
/// sig.connect(|arg| { /* closure */ });
136
149
/// ```
137
150
///
138
- /// - To connect to a method on the object that owns this signal, use [`connect_self()`][Self::connect_self].
151
+ /// # Related APIs
152
+ /// - To connect to a method on the object that owns this signal, use [`connect_self_mut()`][Self::connect_self_mut] or
153
+ /// [`connect_self_gd()`][Self::connect_self_gd].
154
+ /// - To connect to methods on other objects, use [`connect_other_mut()`][Self::connect_other_mut] or
155
+ /// [`connect_other_gd()`][Self::connect_other_gd].
139
156
/// - If you need [`connect flags`](ConnectFlags), call [`flags()`](Self::flags) before this.
140
157
/// - If you need cross-thread signals, use [`connect_sync()`](#method.connect_sync) instead (requires feature "experimental-threads").
141
158
pub fn connect<F , R >( self , mut function: F )
@@ -151,7 +168,8 @@ macro_rules! impl_builder_connect {
151
168
152
169
/// Connect a method with `&mut self` as the first parameter (user classes only).
153
170
///
154
- /// - Use [`connect_self_gd()`][Self::connect_self_gd] to receive `Gd<Self>` instead and avoid implicit `bind_mut()` on emit.
171
+ /// # Related APIs
172
+ /// - Use [`connect_self_gd()`][Self::connect_self_gd] to receive `Gd<Self>` instead and avoid implicit `bind_mut()` on emit. \
155
173
/// For engine classes, `&mut self` is not supported at all.
156
174
/// - To connect to methods on other objects, use [`connect_other_mut()`][Self::connect_other_mut].
157
175
/// - If you need [connect flags](ConnectFlags), call [`flags()`](Self::flags) before this.
@@ -172,6 +190,7 @@ macro_rules! impl_builder_connect {
172
190
173
191
/// Connect a method with `&mut Gd<Self>` as the first parameter (user + engine classes).
174
192
///
193
+ /// # Related APIs
175
194
/// - If your class `C` is user-defined and you'd like to have an automatic `bind_mut()` and receive `&mut self`, then
176
195
/// use [`connect_self_mut()`][Self::connect_self_mut] instead.
177
196
/// - To connect to methods on other objects, use [`connect_other_gd()`][Self::connect_other_gd].
@@ -196,9 +215,10 @@ macro_rules! impl_builder_connect {
196
215
/// - `&OtherC`, as long as `OtherC` is a user class that contains a `Base<T>` field (it implements the
197
216
/// [`WithBaseField`](crate::obj::WithBaseField) trait).
198
217
///
199
- /// ---
200
- ///
201
- /// - To connect to methods on the object that owns this signal, use [`connect_self_mut()`][Self::connect_self].
218
+ /// # Related APIs
219
+ /// - Use [`connect_other_gd()`][Self::connect_other_gd] to receive `Gd<Self>` instead and avoid implicit `bind_mut()` on emit. \
220
+ /// For engine classes, `&mut self` is not supported at all.
221
+ /// - To connect to methods on the object that owns this signal, use [`connect_self_mut()`][Self::connect_self_mut].
202
222
/// - If you need [connect flags](ConnectFlags), call [`flags()`](Self::flags) before this.
203
223
/// - If you need cross-thread signals, use [`connect_sync()`](#method.connect_sync) instead (requires feature "experimental-threads").
204
224
pub fn connect_other_mut<F , R , OtherC >( self , object: & impl ToSignalObj <OtherC >, mut method: F )
@@ -223,8 +243,7 @@ macro_rules! impl_builder_connect {
223
243
/// - `&OtherC`, as long as `OtherC` is a user class that contains a `Base<T>` field (it implements the
224
244
/// [`WithBaseField`](crate::obj::WithBaseField) trait).
225
245
///
226
- /// ---
227
- ///
246
+ /// # Related APIs
228
247
/// - To connect to methods on the object that owns this signal, use [`connect_self_gd()`][Self::connect_self_gd].
229
248
/// - If you need [connect flags](ConnectFlags), call [`flags()`](Self::flags) before this.
230
249
/// - If you need cross-thread signals, use [`connect_sync()`](#method.connect_sync) instead (requires feature "experimental-threads").
@@ -271,14 +290,14 @@ macro_rules! impl_builder_connect {
271
290
} ;
272
291
}
273
292
274
- impl_builder_connect ! ( ) ;
275
- impl_builder_connect ! ( arg0: P0 ) ;
276
- impl_builder_connect ! ( arg0: P0 , arg1: P1 ) ;
277
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 ) ;
278
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 ) ;
279
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 ) ;
280
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 ) ;
281
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 ) ;
282
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 , arg7: P7 ) ;
283
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 , arg7: P7 , arg8: P8 ) ;
284
- impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 , arg7: P7 , arg8: P8 , arg9: P9 ) ;
293
+ impl_builder_connect ! ( # [ doc ( hidden ) ] ) ;
294
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 ) ;
295
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 ) ;
296
+ impl_builder_connect ! ( arg0: P0 , arg1: P1 , arg2: P2 ) ;
297
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 ) ;
298
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 ) ;
299
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 ) ;
300
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 ) ;
301
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 , arg7: P7 ) ;
302
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 , arg7: P7 , arg8: P8 ) ;
303
+ impl_builder_connect ! ( # [ doc ( hidden ) ] arg0: P0 , arg1: P1 , arg2: P2 , arg3: P3 , arg4: P4 , arg5: P5 , arg6: P6 , arg7: P7 , arg8: P8 , arg9: P9 ) ;
0 commit comments