Getters/setters now only accessible in Rust with #[var(pub)]#1458
Merged
Getters/setters now only accessible in Rust with #[var(pub)]#1458
#[var(pub)]#1458Conversation
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.
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1458 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the past, every property automatically created
get_*andset_*methods accessible from Rust.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 tofieldproperty syntax.To use the old behavior,
#[var(pub)]can be used:The
pubemphasizes 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
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. ↩