Unify string parameters across the repo #1037
Open
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.
The types of string parameters across the repo has been regularized according to the following rules that shall be followed from now on:
&str
for things like identifiers. They may specify explicit lifetimes in their types if necessary, but not'static
.impl Into<GodotString>
orimpl Into<NodePath>
depending on the usage, to be consistent with their generated counterparts.Regarding the usage of
&str
in init instead of more specific conversions required by each method:The GDNative API isn't very consistent when it comes to the string types it wants during init. Sometimes, functions may want different types of strings even when they are concepturally similar, like for signal and method registration. This gets more complicated when we add our own library-side logic into the mix, like for the
InitHandle::add_class
family, where allocation is current inevitable even when they are given&'static str
s.It still makes sense to avoid excessive allocation, but that should not get in the way of future development.
'static
in particular is extremely limiting, and there are very few cases of its usage throughout the library's history that we have not since regretted. It shouldn't be the norm but the rare exception.In any case, class registration is something that only run once in the lifecycle of a game, and for the amount of classes most people are using with
gdnative
, we can afford to be slightly inefficient with strings to make our APIs more consistent, less leaky, and easier to stablize and maintain.Close #996