-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
GString refactor #600
GString refactor #600
Conversation
cb4667d
to
5cbef4c
Compare
It's merged :) |
6da3b98
to
fe45283
Compare
More PRs to address breakage caused by this PR:
Probably they should be merged all at once, or before this one |
Next step: change all functions that take |
glib/src/gstring.rs
Outdated
@@ -617,10 +617,10 @@ impl AsRef<[u8]> for GString { | |||
} | |||
|
|||
impl Deref for GString { | |||
type Target = str; | |||
type Target = GStr; |
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 guess we should think about the advantages / disadvantages of this. What does a &GStr
bring in comparison to just having a &str
?
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.
Do we have functions taking GStr
only?
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.
Not yet, see my other comments
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.
Maybe better to use str
for the time being until we make the switch then.
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'll take this out, but gtk-rs/gtk3-rs#739 and gtk-rs/gir#1327 can still be merged without this if you want. They don't break anything.
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.
Sounds like a good idea regardless, yes. More future-proof.
9e2ca9c
to
b2d545a
Compare
Now added |
That was my thought too. We can test it out later with some of the manually implemented functions, and then afterwards work it into gir. |
While you are updating GString traits, maybe we should have Default impls here. See the gstreamer-rs PR for context |
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.
Seems OK to me apart from that final comment
It's here already |
Looks generally nice to me. Are you aware of any drawbacks here or does it all seem nice to you? Also this should probably get a change to
|
a938c6b
to
51f87df
Compare
bf3d2f1
to
f984f68
Compare
Some drawbacks that still persist:
|
f984f68
to
a165b19
Compare
I think those issues are all design issues or can be fixed later, so this is ready now IMO |
a165b19
to
8e5ad99
Compare
8e5ad99
to
f593acb
Compare
For consistency with str::as_bytes. Since we always store the length of the slice we can always do a const conversion like str does.
Optimizes GString to avoid unnecessary checking for interior nul bytes. Interior nul bytes will now only be checked upon request. When converting to C strings, the string will always get truncated to the first nul byte. Since GString can now contain interior nul bytes in some circumstances, its interior representation is now Option<Box<str>>. Also adds custom error types for conversions.
For const std::slice::from_raw_parts, stabilized in rust-lang/rust#97522
Also use Cow<[u8]> as storage to optimize out empty string allocations.
add some PartialEq and PartialOrd implementations for GStr too
These traits can accept both &str or &GStr as an argument. A copy is made when passing &str, but avoided when passing &GStr.
f593acb
to
8fc9217
Compare
Update: See comment #600 (comment) for the general status of this PR.
Original comment: All of these
TryFrom
are panicking when they don't really need to. This is probably going to break some other things, I'd like to check this against gtk-rs and gstreamer-rs at least. Another option is to leave the panickingFrom
traits in and also supportTryFrom
.Also makes
GString
deref as aGStr