diff --git a/glib/src/gstring.rs b/glib/src/gstring.rs index edabfb2a20b0..dc548c739760 100644 --- a/glib/src/gstring.rs +++ b/glib/src/gstring.rs @@ -694,10 +694,17 @@ impl GStringPtr { // rustdoc-stripper-ignore-next /// Returns the corresponding [`&str`]. #[inline] - pub fn to_str(&self) -> &str { + pub fn as_str(&self) -> &str { self.to_gstr().as_str() } + // rustdoc-stripper-ignore-next + /// This is just an alias for [`as_str`]. + #[inline] + pub fn to_str(&self) -> &str { + self + } + // rustdoc-stripper-ignore-next /// Returns the string's C pointer. #[inline] @@ -724,6 +731,15 @@ impl Clone for GStringPtr { } } +impl Deref for GStringPtr { + type Target = str; + + #[inline] + fn deref(&self) -> &str { + self.as_str() + } +} + impl IntoGlibPtr<*mut c_char> for GStringPtr { #[inline] unsafe fn into_glib_ptr(self) -> *mut c_char {