-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify string parameters across the repo
The types of string parameters across the repo has been regularized according to the following rules that shall be followed from now on: - Methods during the init/registration process should take `&str` for things like identifiers. They may specify explicit lifetimes in their types if necessary, but *not* `'static`. - Manually written methods that abstract over, or mimic API methods should take `impl Into<GodotString>` or `impl 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.
- Loading branch information
Showing
9 changed files
with
34 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
//! [@GDScript]: https://docs.godotengine.org/en/stable/classes/[email protected] | ||
use crate::api::{Resource, ResourceLoader}; | ||
use crate::core_types::NodePath; | ||
use crate::core_types::GodotString; | ||
use crate::object::{memory::RefCounted, GodotObject, Ref, SubClass}; | ||
|
||
#[doc(inline)] | ||
|
@@ -52,7 +52,7 @@ pub use gdnative_core::globalscope::*; | |
/// let scene = load::<PackedScene>("res://path/to/Main.tscn").unwrap(); | ||
/// ``` | ||
#[inline] | ||
pub fn load<T>(path: impl Into<NodePath>) -> Option<Ref<T>> | ||
pub fn load<T>(path: impl Into<GodotString>) -> Option<Ref<T>> | ||
where | ||
T: SubClass<Resource> + GodotObject<Memory = RefCounted>, | ||
{ | ||
|