@@ -694,10 +694,18 @@ impl GStringPtr {
694
694
// rustdoc-stripper-ignore-next
695
695
/// Returns the corresponding [`&str`].
696
696
#[ inline]
697
- pub fn to_str ( & self ) -> & str {
697
+ pub fn as_str ( & self ) -> & str {
698
698
self . to_gstr ( ) . as_str ( )
699
699
}
700
700
701
+ // rustdoc-stripper-ignore-next
702
+ /// This is just an alias for [`as_str`].
703
+ #[ inline]
704
+ #[ deprecated = "Use as_str instead" ]
705
+ pub fn to_str ( & self ) -> & str {
706
+ self
707
+ }
708
+
701
709
// rustdoc-stripper-ignore-next
702
710
/// Returns the string's C pointer.
703
711
#[ inline]
@@ -724,6 +732,15 @@ impl Clone for GStringPtr {
724
732
}
725
733
}
726
734
735
+ impl Deref for GStringPtr {
736
+ type Target = str ;
737
+
738
+ #[ inline]
739
+ fn deref ( & self ) -> & str {
740
+ self . as_str ( )
741
+ }
742
+ }
743
+
727
744
impl IntoGlibPtr < * mut c_char > for GStringPtr {
728
745
#[ inline]
729
746
unsafe fn into_glib_ptr ( self ) -> * mut c_char {
@@ -749,7 +766,7 @@ impl fmt::Debug for GStringPtr {
749
766
impl fmt:: Display for GStringPtr {
750
767
#[ inline]
751
768
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
752
- f. write_str ( self . to_str ( ) )
769
+ f. write_str ( self . as_str ( ) )
753
770
}
754
771
}
755
772
@@ -863,7 +880,7 @@ impl Ord for GStringPtr {
863
880
impl PartialOrd < GStringPtr > for String {
864
881
#[ inline]
865
882
fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
866
- Some ( self . as_str ( ) . cmp ( other. to_str ( ) ) )
883
+ Some ( self . as_str ( ) . cmp ( other) )
867
884
}
868
885
}
869
886
@@ -877,7 +894,7 @@ impl PartialOrd<GStringPtr> for GString {
877
894
impl PartialOrd < String > for GStringPtr {
878
895
#[ inline]
879
896
fn partial_cmp ( & self , other : & String ) -> Option < std:: cmp:: Ordering > {
880
- Some ( self . to_str ( ) . cmp ( other) )
897
+ Some ( self . as_str ( ) . cmp ( other) )
881
898
}
882
899
}
883
900
@@ -891,7 +908,7 @@ impl PartialOrd<GString> for GStringPtr {
891
908
impl PartialOrd < GStringPtr > for str {
892
909
#[ inline]
893
910
fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
894
- Some ( self . cmp ( other. to_str ( ) ) )
911
+ Some ( self . cmp ( other. as_str ( ) ) )
895
912
}
896
913
}
897
914
@@ -905,14 +922,14 @@ impl PartialOrd<GStringPtr> for GStr {
905
922
impl PartialOrd < str > for GStringPtr {
906
923
#[ inline]
907
924
fn partial_cmp ( & self , other : & str ) -> Option < std:: cmp:: Ordering > {
908
- Some ( self . to_str ( ) . cmp ( other) )
925
+ Some ( self . as_str ( ) . cmp ( other) )
909
926
}
910
927
}
911
928
912
929
impl PartialOrd < & str > for GStringPtr {
913
930
#[ inline]
914
931
fn partial_cmp ( & self , other : & & str ) -> Option < std:: cmp:: Ordering > {
915
- Some ( self . to_str ( ) . cmp ( other) )
932
+ Some ( self . as_str ( ) . cmp ( other) )
916
933
}
917
934
}
918
935
@@ -933,7 +950,7 @@ impl PartialOrd<&GStr> for GStringPtr {
933
950
impl PartialOrd < GStringPtr > for & str {
934
951
#[ inline]
935
952
fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
936
- Some ( self . cmp ( & other. to_str ( ) ) )
953
+ Some ( self . cmp ( & other. as_str ( ) ) )
937
954
}
938
955
}
939
956
@@ -954,7 +971,7 @@ impl AsRef<GStringPtr> for GStringPtr {
954
971
impl std:: hash:: Hash for GStringPtr {
955
972
#[ inline]
956
973
fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
957
- self . to_str ( ) . hash ( state) ;
974
+ self . as_str ( ) . hash ( state) ;
958
975
}
959
976
}
960
977
0 commit comments