Struct ConnectBuilder
pub struct ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>where
CSig: GodotClass,{ /* private fields */ }
Expand description
Type-state builder for customizing signal connections.
Allows a high degree of customization for connecting signals, while maintaining complete type safety.
#[doc(hidden)]
, but it would make
things harder to understand. Thus, try not to name the ConnectBuilder
type in your code; most connection setup doesn't need it.
§Builder stages
The builder API has a well-defined flow and is separated in stages. In each stage, you have certain builder methods available that you can or must call, before advancing to the next stage. Check the instructions.
§Stage 1 (required)
Choose one:
function
: Connect a global/associated function or a closure.object_self
: If you want to connect a method (in stage 2), running on the same object as the signal.object
: If you want to connect a method, running on a separate object.
§Stage 2 (conditional)
Required iff (if and only if) object_self
or object
was called in stage 1.
method_mut
: Connect a&mut self
method.method_immut
: Connect a&self
method.
§Stage 3
All these methods are optional, and they can be combined.
sync
: If the signal connection should be callable across threads.
RequiresSend
+Sync
bounds on the provided function/method, and is only available for theexperimental-threads
Cargo feature.name
: Name of theCallable
(for debug purposes).
If not specified, the Rust function name is used. This is typically a good default, but not very readable for closures.flags
: Provide one or multipleConnectFlags
, possibly combined with bitwise OR.
§Final stage
done
: Finalize the connection. Consumes the builder and registers the signal with Godot.
Implementations§
§impl<'ts, 'c, CSig, Ps> ConnectBuilder<'ts, 'c, CSig, (), Ps, ()>where
CSig: WithBaseField,
Ps: ParamTuple,
impl<'ts, 'c, CSig, Ps> ConnectBuilder<'ts, 'c, CSig, (), Ps, ()>where
CSig: WithBaseField,
Ps: ParamTuple,
pub fn function<F>(
self,
function: F,
) -> ConnectBuilder<'ts, 'c, CSig, (), Ps, impl FnMut(&[&Variant]) + 'static>where
F: SignalReceiver<(), Ps>,
pub fn function<F>(
self,
function: F,
) -> ConnectBuilder<'ts, 'c, CSig, (), Ps, impl FnMut(&[&Variant]) + 'static>where
F: SignalReceiver<(), Ps>,
Stage 1: global/associated function or closure.
pub fn object_self(self) -> ConnectBuilder<'ts, 'c, CSig, Gd<CSig>, Ps, ()>
pub fn object_self(self) -> ConnectBuilder<'ts, 'c, CSig, Gd<CSig>, Ps, ()>
Stage 1: prepare for a method taking self
(the class declaring the #[signal]
).
pub fn object<C>(
self,
object: &Gd<C>,
) -> ConnectBuilder<'ts, 'c, CSig, Gd<C>, Ps, ()>where
C: GodotClass,
pub fn object<C>(
self,
object: &Gd<C>,
) -> ConnectBuilder<'ts, 'c, CSig, Gd<C>, Ps, ()>where
C: GodotClass,
Stage 1: prepare for a method taking any Gd<T>
object.
§impl<'ts, 'c, CSig, CRcv, Ps> ConnectBuilder<'ts, 'c, CSig, Gd<CRcv>, Ps, ()>
impl<'ts, 'c, CSig, CRcv, Ps> ConnectBuilder<'ts, 'c, CSig, Gd<CRcv>, Ps, ()>
pub fn method_mut<F>(
self,
method_with_mut_self: F,
) -> ConnectBuilder<'ts, 'c, CSig, (), Ps, impl FnMut(&[&Variant])>where
CRcv: GodotClass<Declarer = DeclUser> + Bounds,
F: for<'c_rcv> SignalReceiver<&'c_rcv mut CRcv, Ps>,
pub fn method_mut<F>(
self,
method_with_mut_self: F,
) -> ConnectBuilder<'ts, 'c, CSig, (), Ps, impl FnMut(&[&Variant])>where
CRcv: GodotClass<Declarer = DeclUser> + Bounds,
F: for<'c_rcv> SignalReceiver<&'c_rcv mut CRcv, Ps>,
Stage 2: method taking &mut self
.
pub fn method_immut<F>(
self,
method_with_shared_self: F,
) -> ConnectBuilder<'ts, 'c, CSig, (), Ps, impl FnMut(&[&Variant])>where
CRcv: GodotClass<Declarer = DeclUser> + Bounds,
F: for<'c_rcv> SignalReceiver<&'c_rcv CRcv, Ps>,
pub fn method_immut<F>(
self,
method_with_shared_self: F,
) -> ConnectBuilder<'ts, 'c, CSig, (), Ps, impl FnMut(&[&Variant])>where
CRcv: GodotClass<Declarer = DeclUser> + Bounds,
F: for<'c_rcv> SignalReceiver<&'c_rcv CRcv, Ps>,
Stage 2: method taking &self
.
§impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>where
CSig: WithBaseField,
Ps: ParamTuple,
GodotFn: FnMut(&[&Variant]) -> Result<Variant, ()> + 'static,
impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>where
CSig: WithBaseField,
Ps: ParamTuple,
GodotFn: FnMut(&[&Variant]) -> Result<Variant, ()> + 'static,
pub fn sync(
self,
) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, impl FnMut(&[&Variant])>
Available on crate feature experimental-threads
only.
pub fn sync( self, ) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, impl FnMut(&[&Variant])>
experimental-threads
only.Stage 3: allow signal to be called across threads.
Requires Send
+ Sync
bounds on the previously provided function/method, and is only available for the experimental-threads
Cargo feature.
pub fn name(
self,
name: impl AsArg<GString>,
) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
pub fn name( self, name: impl AsArg<GString>, ) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
Stage 3: Name of the Callable
, mostly used for debugging.
If not provided, the Rust type name of the function/method is used.
pub fn flags(
self,
flags: ConnectFlags,
) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
pub fn flags( self, flags: ConnectFlags, ) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
Stage 3: add one or multiple flags to the connection, possibly combined with |
operator.
pub fn done(self)
pub fn done(self)
Finalize the builder.
Actually connects the signal with the provided function/method. Consumes this builder instance and returns the mutable borrow of
the parent TypedSignal
for further use.