Skip to content

ZST type for synthetic properties #1151

Open
@Bromeon

Description

@Bromeon

We should implement a ZST type that can be used as a field, like gdnative's Property<T>.
This type will not store any value itself, but delegate to the custom getter and setter.

Example:

#[derive(GodotClass)]
struct MyClass {
    #[var(get)]
    synthetic_string: Property<GString>,
}

#[godot_api]
impl MyClass {
    #[func]
    fn get_synthetic_string(&self) -> GString {
        // Derive on-the-fly from instance state.
    }
}

I originally thought this might be interesting as a workaround for #[constant] which is limited to integers. However, properties make impractical constants as they need a pre-existing instance. Static functions are better suited.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions