PropertyInfo

Struct PropertyInfo 

pub struct PropertyInfo {
    pub variant_type: VariantType,
    pub class_id: ClassId,
    pub property_name: StringName,
    pub hint_info: PropertyHintInfo,
    pub usage: PropertyUsageFlags,
}
Expand description

Describes a property’s type, name and metadata for Godot.

PropertyInfo is used throughout the Godot binding to describe properties, method parameters and return types.

This is a high-level abstraction over the low-level FFI type sys::GDExtensionPropertyInfo. Unlike the FFI version which only stores pointers, PropertyInfo owns its data, ensuring it remains valid for the lifetime of the struct.

See also MethodInfo for describing method signatures and ClassId for type-IDs of Godot classes.

§Construction

For most use cases, prefer the convenience constructors:

§Example

use godot::meta::{PropertyInfo, PropertyHintInfo, ClassId};
use godot::builtin::{StringName, VariantType};
use godot::global::PropertyUsageFlags;

// Integer property without a specific class
let count_property = PropertyInfo {
    variant_type: VariantType::INT,
    class_id: ClassId::none(),  // Only OBJECT types need a real class ID.
    property_name: StringName::from("count"),
    hint_info: PropertyHintInfo::none(),
    usage: PropertyUsageFlags::DEFAULT,
};

Here, class_id is set to ClassId::none() because integer properties do not require a specific class. For objects, you can use ClassId::new_cached::<T>(...) if you have a Rust type, or ClassId::new_dynamic(...) for dynamic contexts and script classes.

Fields§

§variant_type: VariantType

Type of the property.

For objects, this should be set to VariantType::OBJECT and use the class_id field to specify the actual class.
For generic Variant properties, use VariantType::NIL.

§class_id: ClassId

The specific class identifier for object-typed properties in Godot.

This is only relevant when variant_type is set to VariantType::OBJECT.

§Example

use godot::meta::ClassId;
use godot::classes::Node3D;
use godot::obj::GodotClass; // Trait method ::class_id().

let none_id = ClassId::none();                      // For built-ins (not classes).
let static_id = Node3D::class_id();                 // For classes with a Rust type.
let dynamic_id = ClassId::new_dynamic("MyScript");  // For runtime class names.
§property_name: StringName

The name of this property as it appears in Godot’s object system.

§hint_info: PropertyHintInfo

Additional type information and validation constraints for this property.

Use functions from export_info_functions to create common hints, or PropertyHintInfo::none() for no hints.

See PropertyHintInfo struct in Rust, as well as PropertyHint in the official Godot documentation.

§usage: PropertyUsageFlags

Flags controlling how this property should be used and displayed by the Godot engine.

Common values:

See also PropertyUsageFlags in the official Godot documentation for a complete list of flags.

Implementations§

§

impl PropertyInfo

pub fn new_var<T>(property_name: &str) -> PropertyInfo
where T: Var,

Create a new PropertyInfo representing a property named property_name with type T automatically.

This will generate property info equivalent to what a #[var] attribute would produce.

pub fn new_export<T>(property_name: &str) -> PropertyInfo
where T: Export,

Create a new PropertyInfo for an exported property named property_name with type T automatically.

This will generate property info equivalent to what an #[export] attribute would produce.

pub fn with_hint_info(self, hint_info: PropertyHintInfo) -> PropertyInfo

Change the hint and hint_string to be the given hint_info.

See export_info_functions for functions that return appropriate PropertyHintInfos for various Godot annotations.

§Example

Creating an @export_range property.

use godot::register::property::export_info_functions;
use godot::meta::PropertyInfo;

let property = PropertyInfo::new_export::<f64>("my_range_property")
    .with_hint_info(export_info_functions::export_range(
        0.0,
        10.0,
        Some(0.1),
        false,
        false,
        false,
        false,
        false,
        false,
        Some("mm".to_string()),
    ));

pub fn new_group(group_name: &str, group_prefix: &str) -> PropertyInfo

Create a new PropertyInfo representing a group in Godot.

See EditorInspector in Godot for more information.

pub fn new_subgroup(subgroup_name: &str, subgroup_prefix: &str) -> PropertyInfo

Create a new PropertyInfo representing a subgroup in Godot.

See EditorInspector in Godot for more information.

Trait Implementations§

§

impl Clone for PropertyInfo

§

fn clone(&self) -> PropertyInfo

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 PropertyInfo

§

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.