Skip to content

Getters/setters now only accessible in Rust with #[var(pub)]#1458

Merged
Bromeon merged 1 commit intomasterfrom
qol/var-explicit-pub
Dec 30, 2025
Merged

Getters/setters now only accessible in Rust with #[var(pub)]#1458
Bromeon merged 1 commit intomasterfrom
qol/var-explicit-pub

Conversation

@Bromeon
Copy link
Copy Markdown
Member

@Bromeon Bromeon commented Dec 29, 2025

In the past, every property automatically created get_* and set_* methods accessible from Rust.

#[var]
field: i64,

// later:
obj.bind_mut().set_field(1234);
let i = obj.bind().get_field();

After this PR, the Rust-side getter/setter will no longer be generated. The GDScript getter/setter are still accessible as get_field/set_field, in addition to field property syntax.

To use the old behavior, #[var(pub)] can be used:

#[var(pub)]
field: i64,

The pub emphasizes that this property is public (in Rust). Either way it's always possible to access it through the Godot engine -- slightly more involved via scripts or reflection. This change cuts down on a potentially large number of uselessly generated methods (i.e. compile time1) and can improve encapsulation, while still allowing people who need public accessors to opt in.

Furthermore, this is not a hard breakage: the old methods continue to be generated until v0.6 and will issue a deprecation warning when accessed without #[var(pub)], including migration instructions.

Came up during #1454.

Footnotes

  1. in the current implementation, methods are still generated but hidden. However, them not being public allows us to transparently find optimized representations without affecting user code.

Reduces the amount of potentially unused code generation and can improve
encapsulation, while still allowing people who need public accessors to opt in.

Not hard breakage; will issue deprecation warnings for old generated method names.
@Bromeon Bromeon added this to the 0.5 milestone Dec 29, 2025
@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: register Register classes, functions and other symbols to GDScript labels Dec 29, 2025
@GodotRust
Copy link
Copy Markdown

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1458

@Bromeon Bromeon added this pull request to the merge queue Dec 30, 2025
Merged via the queue into master with commit f8b5f4c Dec 30, 2025
20 checks passed
@Bromeon Bromeon deleted the qol/var-explicit-pub branch December 30, 2025 13:06
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 quality-of-life No new functionality, but improves ergonomics/internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants