Skip to content
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

glib/GStringPtr: Add as_str() and Deref<Target=&str> #1181

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

cgwalters
Copy link
Contributor

I was updating some code to glib 0.18 and we were previously using as_str() - which is what the default Rust nomenclature for an infallible reference-to-reference conversion uses.

The to_str() is used for fallible conversions
(e.g. https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.to_str) which this is not.

@cgwalters
Copy link
Contributor Author

cgwalters commented Sep 12, 2023

Also BTW I didn't test this locally as I'm hitting a crate build error locally; I haven't dug in yet

EDIT: See #1185

walters@toolbox /v/s/w/s/g/g/gtk-rs-core (gstring-as-str)> cargo check
    Checking glib v0.19.0 (/var/srv/walters/src/github/gtk-rs/gtk-rs-core/glib)
error[E0277]: `T` doesn't implement `Debug`
    --> glib/src/gstring.rs:1318:12
     |
1318 | pub struct GStringNoTrailingNulError<T>(T);
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
     |
note: required for `GStringNoTrailingNulError<T>` to implement `Debug`
    --> glib/src/gstring.rs:1316:50
     |
1316 | #[derive(thiserror::Error, Clone, PartialEq, Eq, Debug)]
     |                                                  ^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `std::error::Error`
    --> /builddir/build/BUILD/rustc-1.72.0-src/library/core/src/error.rs:32:1
     = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
     |
1318 | pub struct GStringNoTrailingNulError<T: std::fmt::Debug>(T);
     |                                       +++++++++++++++++

error[E0277]: `T` doesn't implement `Debug`
    --> glib/src/gstring.rs:1335:12
     |
1335 | pub struct GStringInteriorNulError<T>(T, GStrInteriorNulError);
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
     |
note: required for `GStringInteriorNulError<T>` to implement `Debug`
    --> glib/src/gstring.rs:1333:50
     |
1333 | #[derive(thiserror::Error, Clone, PartialEq, Eq, Debug)]
     |                                                  ^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `std::error::Error`
    --> /builddir/build/BUILD/rustc-1.72.0-src/library/core/src/error.rs:32:1
     = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
     |
1335 | pub struct GStringInteriorNulError<T: std::fmt::Debug>(T, GStrInteriorNulError);
     |                                     +++++++++++++++++

error[E0277]: `T` doesn't implement `Debug`
    --> glib/src/gstring.rs:1358:12
     |
1358 | pub struct GStringUtf8Error<T>(T, std::str::Utf8Error);
     |            ^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
     |
note: required for `GStringUtf8Error<T>` to implement `Debug`
    --> glib/src/gstring.rs:1356:50
     |
1356 | #[derive(thiserror::Error, Clone, PartialEq, Eq, Debug)]
     |                                                  ^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `std::error::Error`
    --> /builddir/build/BUILD/rustc-1.72.0-src/library/core/src/error.rs:32:1
     = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
     |
1358 | pub struct GStringUtf8Error<T: std::fmt::Debug>(T, std::str::Utf8Error);
     |                              +++++++++++++++++

error[E0277]: `T` doesn't implement `Debug`
    --> glib/src/gstring.rs:1379:10
     |
1379 | pub enum GStringFromError<T> {
     |          ^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
     |
note: required for `GStringFromError<T>` to implement `Debug`
    --> glib/src/gstring.rs:1378:28
     |
1378 | #[derive(thiserror::Error, Debug)]
     |                            ^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `std::error::Error`
    --> /builddir/build/BUILD/rustc-1.72.0-src/library/core/src/error.rs:32:1
     = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
     |
1379 | pub enum GStringFromError<T: std::fmt::Debug> {
     |                            +++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `glib` (lib) due to 4 previous errors

@sdroege
Copy link
Member

sdroege commented Sep 25, 2023

What's the status here?

@cgwalters
Copy link
Contributor Author

cgwalters commented Sep 25, 2023

Now that I can build locally, updated to fix the infinite recursion in Deref and I think this should be good to go. There's one minor outstanding question.

@bilelmoussaoui bilelmoussaoui added the needs-backport PR needs backporting to the current stable branch label Sep 25, 2023
I was updating some code to glib 0.18 and we were previously
using `as_str()` - which is what the default Rust nomenclature
for an *infallible* reference-to-reference conversion uses.

The `to_str()` is used for fallible conversions
(e.g. https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.to_str)
which this is not.
@sdroege sdroege merged commit 9b61929 into gtk-rs:master Sep 25, 2023
48 checks passed
@sdroege sdroege removed the needs-backport PR needs backporting to the current stable branch label Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants