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.

Warning: Exact type parameters are subject to change and not part of the public API. We could annotate #[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.

§Stage 3

All these methods are optional, and they can be combined.

  • sync: If the signal connection should be callable across threads.
    Requires Send + Sync bounds on the provided function/method, and is only available for the experimental-threads Cargo feature.
  • name: Name of the Callable (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 multiple ConnectFlags, 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,

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

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,

Stage 1: prepare for a method taking any Gd<T> object.

§

impl<'ts, 'c, CSig, CRcv, Ps> ConnectBuilder<'ts, 'c, CSig, Gd<CRcv>, Ps, ()>
where CSig: WithBaseField, CRcv: GodotClass, Ps: ParamTuple,

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

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,

pub fn sync( self, ) -> ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, impl FnMut(&[&Variant])>
where GodotFn: Send + Sync,

Available on crate feature 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>

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>

Stage 3: add one or multiple flags to the connection, possibly combined with | operator.

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.

Auto Trait Implementations§

§

impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> Freeze for ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
where CRcv: Freeze, GodotFn: Freeze,

§

impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> RefUnwindSafe for ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
where CRcv: RefUnwindSafe, GodotFn: RefUnwindSafe, Ps: RefUnwindSafe, CSig: RefUnwindSafe,

§

impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> !Send for ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>

§

impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> !Sync for ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>

§

impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> Unpin for ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>
where CRcv: Unpin, GodotFn: Unpin,

§

impl<'ts, 'c, CSig, CRcv, Ps, GodotFn> !UnwindSafe for ConnectBuilder<'ts, 'c, CSig, CRcv, Ps, GodotFn>

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.