-
-
Notifications
You must be signed in to change notification settings - Fork 224
Add many GString
/StringName
methods
#980
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
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-980 |
c0c2580
to
5d7a7fe
Compare
5d7a7fe
to
6c89d57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice if we could like have some feature where we can change at least the return value of some auto-generated functions.
Like maybe is_builtin_method_exposed
could return an Option<ExposeOptions>
or something, and ExposeOptions
is an enum with variants like
enum ExposeOptions {
Default,
Ordering, // -1 = Less, 0 = Equal, 1 = Greater
Option,
Usize,
}
Which will have the code attempt to change the return value to that type? idk
maybe at least group the functions somehow for now by which should remain unchanged and which should have their signature modified so we can more easily change it after implementing something like the above.
Otherwise i think this is pretty good.
/// _Godot equivalent: `length`_ | ||
pub fn len(&self) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// _Godot equivalent: `length`_ | |
pub fn len(&self) -> usize { | |
/// _Godot equivalent: `length`_ | |
#[doc(alias = "length")] | |
pub fn len(&self) -> usize { |
| ("String", "casecmp_to") | ||
| ("String", "nocasecmp_to") | ||
| ("String", "naturalcasecmp_to") | ||
| ("String", "naturalnocasecmp_to") | ||
| ("String", "filecasecmp_to") | ||
| ("String", "filenocasecmp_to") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these functions return a Ordering
? They do return -1
, 0
, 1
corresponding to less/equal/greater. Same with StringName
below
| ("String", "get_slice") | ||
| ("String", "get_slicec") | ||
| ("String", "get_slice_count") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a some functions like these that can fail that should maybe return Option<T>
instead, though get_slice
actually is a bit weird in that there are two failure cases that have different behavior.
38385b7
to
07a553c
Compare
1c1e47f
to
f70341d
Compare
f70341d
to
e63f68b
Compare
16afc0a
to
06b0e49
Compare
06b0e49
to
2055bdf
Compare
So, I added a ton of methods, including several manually redefined ones. See initial post for API design. |
Populates
GString
+StringName
with the majority of generated methods from Godot.I made multiple API design choices to make string operations more idiomatic in Rust:
Option::None
instead of-1
for "not found".split
+find
, instead of proliferation offind/findn/rfind/rfindn
and x2 with_from
index.usize
instead ofi64
where integers are unsigned offsets/indices.std::ops::RangeBounds
instead of inconsistentfrom
,(from, to)
,(from, len)
conventions used in Godot.char
instead ofi64
when a Unicode code point is required.std::cmp::Ordering
when the result is -1, 0 or 1 depending on ordering relation.with_*
overload for rarely used alternatives (format
+format_with_placeholder
).match
->match_glob
).Added unit tests for most things.
For the
[natural|file][no]casecmp_to
methods, I currently left the original methods, but technically they could use a builder as well. Might change in the future...