godot::prelude

Struct Signal

pub struct Signal { /* private fields */ }
Expand description

A Signal represents a signal of an Object instance in Godot.

Signals are composed of a reference to an Object and the name of the signal on this object.

§Godot docs

Signal (stable)

Implementations§

§

impl Signal

pub fn from_object_signal<T, S>(object: &Gd<T>, signal_name: S) -> Signal
where T: GodotClass, S: AsArg<StringName>,

Create a signal for the signal object::signal_name.

Godot equivalent: Signal(Object object, StringName signal)

pub fn invalid() -> Signal

Creates an invalid/empty signal that cannot be called.

Godot equivalent: Signal()

pub fn connect(&self, callable: &Callable, flags: i64) -> Error

Connects this signal to the specified callable.

Optional flags can be also added to configure the connection’s behavior (see ConnectFlags constants). You can provide additional arguments to the connected callable by using Callable::bind.

A signal can only be connected once to the same Callable. If the signal is already connected, returns Error::ERR_INVALID_PARAMETER and pushes an error message, unless the signal is connected with ConnectFlags::REFERENCE_COUNTED. To prevent this, use Self::is_connected first to check for existing connections.

pub fn disconnect(&self, callable: &Callable)

Disconnects this signal from the specified Callable.

If the connection does not exist, generates an error. Use Self::is_connected to make sure that the connection exists.

pub fn emit(&self, varargs: &[Variant])

Emits this signal.

All Callables connected to this signal will be triggered.

pub fn connections(&self) -> Array<Dictionary>

Returns an Array of connections for this signal.

Each connection is represented as a Dictionary that contains three entries:

  • signal is a reference to this Signal;
  • callable is a reference to the connected Callable;
  • flags is a combination of ConnectFlags.

Godot equivalent: get_connections

pub fn name(&self) -> StringName

Returns the name of the signal.

pub fn object(&self) -> Option<Gd<Object>>

Returns the object to which this signal belongs.

Returns None when this signal doesn’t have any object, or the object is dead. You can differentiate these two situations using object_id().

Godot equivalent: get_object

pub fn object_id(&self) -> Option<InstanceId>

Returns the ID of this signal’s object, see also Gd::instance_id.

Returns None when this signal doesn’t have any object.

If the pointed-to object is dead, the ID will still be returned. Use object() to check for liveness.

Godot equivalent: get_object_id

pub fn is_connected(&self, callable: &Callable) -> bool

Returns true if the specified Callable is connected to this signal.

pub fn is_null(&self) -> bool

Returns true if the signal’s name does not exist in its object, or the object is not valid.

Trait Implementations§

§

impl Clone for Signal

§

fn clone(&self) -> Signal

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Signal

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Display for Signal

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Drop for Signal

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl FromGodot for Signal

§

fn try_from_godot( via: <Signal as GodotConvert>::Via, ) -> Result<Signal, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl GodotConvert for Signal

§

type Via = Signal

The type through which Self is represented in Godot.
§

impl ParamType for Signal

§

fn owned_to_arg<'v>(self) -> <Signal as ParamType>::Arg<'v>

Converts an owned value to the canonical argument type, which can be passed to impl AsArg<T>. Read more
§

impl PartialEq for Signal

§

fn eq(&self, other: &Signal) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl ToGodot for Signal

§

type ToVia<'v> = <Signal as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
§

fn to_godot(&self) -> <Signal as ToGodot>::ToVia<'_>

Converts this type to the Godot type by reference, usually by cloning.
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl Var for Signal

§

fn get_property(&self) -> <Signal as GodotConvert>::Via

§

fn set_property(&mut self, value: <Signal as GodotConvert>::Via)

§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
§

impl ArrayElement for Signal

§

impl<'r> AsArg<Signal> for &'r Signal

§

impl GodotType for Signal

Auto Trait Implementations§

§

impl Freeze for Signal

§

impl RefUnwindSafe for Signal

§

impl !Send for Signal

§

impl !Sync for Signal

§

impl Unpin for Signal

§

impl UnwindSafe for Signal

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.