Skip to content

ZST type for synthetic properties #1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Bromeon opened this issue May 1, 2025 · 1 comment
Open

ZST type for synthetic properties #1151

Bromeon opened this issue May 1, 2025 · 1 comment
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library

Comments

@Bromeon
Copy link
Member

Bromeon commented May 1, 2025

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.

@Bromeon Bromeon added c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library labels May 1, 2025
@Yarwin
Copy link
Contributor

Yarwin commented May 2, 2025

Sounds cool.

I would propose calling it Placeholder<Type> instead. Property is something concrete in godot, so it might be a bit confusing.

Should getter/setter be obligatory to implement? If not, it would take care of some new/quirky PropertyFlags that are not handled by godot-rust yet – right now such examples could be group and categories (see: #226 (comment)) (not as a "real" supported solution ofc, more like band-aid before we figure out the real thing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library
Projects
None yet
Development

No branches or pull requests

2 participants