MethodInfo

Struct MethodInfo 

pub struct MethodInfo {
    pub id: i32,
    pub method_name: StringName,
    pub class_name: ClassId,
    pub return_type: PropertyInfo,
    pub arguments: Vec<PropertyInfo>,
    pub default_arguments: Vec<Variant>,
    pub flags: MethodFlags,
}
Expand description

Describes a method’s signature and metadata required by the Godot engine.

Primarily used when implementing custom script instances via the ScriptInstance trait. It contains metadata Godot needs to describe and call a method.

MethodInfo is a high-level abstraction over the low-level FFI type sys::GDExtensionMethodInfo.

See also PropertyInfo for describing individual method parameters and return types.

§Example

use godot::meta::{MethodInfo, PropertyInfo, PropertyHintInfo, ClassId};
use godot::builtin::{StringName, Variant, VariantType};
use godot::global::{MethodFlags, PropertyUsageFlags};
use godot::classes::Node2D;
use godot::obj::GodotClass; // Trait method ::class_id().

// Describe a Godot method (`World` is a GDScript class):
//   func spawn_at(world: World, position: Vector2) -> Node2D.
let method = MethodInfo {
    id: 0,
    method_name: StringName::from("spawn_at"),
    class_name: ClassId::none(),
    return_type: PropertyInfo {
        variant_type: VariantType::OBJECT,
        class_id: Node2D::class_id(),
        property_name: StringName::default(), // Return types use empty string.
        hint_info: PropertyHintInfo::none(),
        usage: PropertyUsageFlags::DEFAULT,
    },
    arguments: vec![
        PropertyInfo {
            variant_type: VariantType::OBJECT,
            class_id: ClassId::new_dynamic("World"),
            property_name: StringName::from("world"),
            hint_info: PropertyHintInfo::none(),
            usage: PropertyUsageFlags::DEFAULT,
        },
        PropertyInfo {
            variant_type: VariantType::VECTOR2,
            class_id: ClassId::none(),
            property_name: StringName::from("position"),
            hint_info: PropertyHintInfo::none(),
            usage: PropertyUsageFlags::DEFAULT,
        },
    ],
    default_arguments: vec![],
    flags: MethodFlags::DEFAULT,
};

Fields§

§id: i32

Unique identifier for the method within its class.

This ID can be used to distinguish between methods and is typically set by the implementation. For script instances, this is often just a sequential index.

§method_name: StringName

The name of the method, as it appears in Godot.

§class_name: ClassId

The class this method belongs to.

For script-defined methods, this is typically the script’s class ID obtained via ClassId::new_dynamic(). Use ClassId::none() if the class is not applicable or unknown.

§return_type: PropertyInfo

Description of the method’s return type.

See PropertyInfo for how to construct type information. For methods that don’t return a value (void), use VariantType::NIL.

§arguments: Vec<PropertyInfo>

Descriptions of each method parameter.

Each element describes one parameter’s type, name, and metadata. The order matches the parameter order in the method signature.

§default_arguments: Vec<Variant>

Default values for parameters with defaults.

Contains the actual default Variant values for parameters that have them. The length of this vector is typically less than or equal to arguments.len(), containing defaults only for trailing parameters.

§flags: MethodFlags

Method flags controlling behavior and access.

See MethodFlags for available options like NORMAL, VIRTUAL, CONST, etc.

Trait Implementations§

§

impl Clone for MethodInfo

§

fn clone(&self) -> MethodInfo

Returns a duplicate 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 MethodInfo

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.