@@ -684,6 +684,24 @@ impl GStringPtr {
684
684
pub fn to_str ( & self ) -> & str {
685
685
self . to_gstr ( ) . as_str ( )
686
686
}
687
+
688
+ // rustdoc-stripper-ignore-next
689
+ /// Returns the string's C pointer.
690
+ #[ inline]
691
+ pub const fn as_ptr ( & self ) -> * const c_char {
692
+ self . 0 . as_ptr ( )
693
+ }
694
+
695
+ // rustdoc-stripper-ignore-next
696
+ /// Wrapper around `libc::strcmp` returning `Ordering`.
697
+ ///
698
+ /// # Safety
699
+ ///
700
+ /// `a` and `b` must be non-null pointers to nul-terminated C strings.
701
+ #[ inline]
702
+ unsafe fn strcmp ( a : * const c_char , b : * const c_char ) -> Ordering {
703
+ from_glib ( libc:: strcmp ( a, b) )
704
+ }
687
705
}
688
706
689
707
impl Clone for GStringPtr {
@@ -693,6 +711,13 @@ impl Clone for GStringPtr {
693
711
}
694
712
}
695
713
714
+ impl IntoGlibPtr < * mut c_char > for GStringPtr {
715
+ #[ inline]
716
+ unsafe fn into_glib_ptr ( self ) -> * mut c_char {
717
+ self . 0 . as_ptr ( )
718
+ }
719
+ }
720
+
696
721
impl Drop for GStringPtr {
697
722
#[ inline]
698
723
fn drop ( & mut self ) {
@@ -704,7 +729,7 @@ impl Drop for GStringPtr {
704
729
705
730
impl fmt:: Debug for GStringPtr {
706
731
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
707
- f . write_str ( self . to_str ( ) )
732
+ < & GStr as fmt :: Debug > :: fmt ( & self . to_gstr ( ) , f )
708
733
}
709
734
}
710
735
@@ -720,105 +745,105 @@ impl Eq for GStringPtr {}
720
745
impl PartialEq for GStringPtr {
721
746
#[ inline]
722
747
fn eq ( & self , other : & GStringPtr ) -> bool {
723
- self . to_gstr ( ) == other . to_gstr ( )
748
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
724
749
}
725
750
}
726
751
727
752
impl PartialEq < GStringPtr > for String {
728
753
#[ inline]
729
754
fn eq ( & self , other : & GStringPtr ) -> bool {
730
- self . as_str ( ) == other . to_str ( )
755
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
731
756
}
732
757
}
733
758
734
759
impl PartialEq < GStringPtr > for GString {
735
760
#[ inline]
736
761
fn eq ( & self , other : & GStringPtr ) -> bool {
737
- self . as_str ( ) == other . to_str ( )
762
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
738
763
}
739
764
}
740
765
741
766
impl PartialEq < str > for GStringPtr {
742
767
#[ inline]
743
768
fn eq ( & self , other : & str ) -> bool {
744
- self . to_str ( ) == other
769
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
745
770
}
746
771
}
747
772
748
773
impl PartialEq < & str > for GStringPtr {
749
774
#[ inline]
750
775
fn eq ( & self , other : & & str ) -> bool {
751
- self . to_str ( ) == * other
776
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
752
777
}
753
778
}
754
779
755
780
impl PartialEq < GStr > for GStringPtr {
756
781
#[ inline]
757
782
fn eq ( & self , other : & GStr ) -> bool {
758
- self . to_gstr ( ) == other
783
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
759
784
}
760
785
}
761
786
762
787
impl PartialEq < & GStr > for GStringPtr {
763
788
#[ inline]
764
789
fn eq ( & self , other : & & GStr ) -> bool {
765
- self . to_gstr ( ) == * other
790
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
766
791
}
767
792
}
768
793
769
794
impl PartialEq < GStringPtr > for & str {
770
795
#[ inline]
771
796
fn eq ( & self , other : & GStringPtr ) -> bool {
772
- * self == other . to_str ( )
797
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
773
798
}
774
799
}
775
800
776
801
impl PartialEq < GStringPtr > for & GStr {
777
802
#[ inline]
778
803
fn eq ( & self , other : & GStringPtr ) -> bool {
779
- self . as_str ( ) == other . to_str ( )
804
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
780
805
}
781
806
}
782
807
783
808
impl PartialEq < String > for GStringPtr {
784
809
#[ inline]
785
810
fn eq ( & self , other : & String ) -> bool {
786
- self . to_str ( ) == other . as_str ( )
811
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
787
812
}
788
813
}
789
814
790
815
impl PartialEq < GString > for GStringPtr {
791
816
#[ inline]
792
817
fn eq ( & self , other : & GString ) -> bool {
793
- self . to_str ( ) == other . as_str ( )
818
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
794
819
}
795
820
}
796
821
797
822
impl PartialEq < GStringPtr > for str {
798
823
#[ inline]
799
824
fn eq ( & self , other : & GStringPtr ) -> bool {
800
- self == other . to_str ( )
825
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
801
826
}
802
827
}
803
828
804
829
impl PartialEq < GStringPtr > for GStr {
805
830
#[ inline]
806
831
fn eq ( & self , other : & GStringPtr ) -> bool {
807
- self == other . to_gstr ( )
832
+ self . partial_cmp ( other ) == Some ( Ordering :: Equal )
808
833
}
809
834
}
810
835
811
836
impl PartialOrd < GStringPtr > for GStringPtr {
812
837
#[ inline]
813
838
fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
814
- Some ( self . to_gstr ( ) . cmp ( other. to_gstr ( ) ) )
839
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
815
840
}
816
841
}
817
842
818
843
impl Ord for GStringPtr {
819
844
#[ inline]
820
845
fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
821
- self . to_gstr ( ) . cmp ( other. to_gstr ( ) )
846
+ unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) }
822
847
}
823
848
}
824
849
@@ -832,21 +857,21 @@ impl PartialOrd<GStringPtr> for String {
832
857
impl PartialOrd < GStringPtr > for GString {
833
858
#[ inline]
834
859
fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
835
- Some ( self . as_str ( ) . cmp ( other. to_str ( ) ) )
860
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
836
861
}
837
862
}
838
863
839
864
impl PartialOrd < String > for GStringPtr {
840
865
#[ inline]
841
866
fn partial_cmp ( & self , other : & String ) -> Option < std:: cmp:: Ordering > {
842
- Some ( self . to_str ( ) . cmp ( other. as_str ( ) ) )
867
+ Some ( self . to_str ( ) . cmp ( other) )
843
868
}
844
869
}
845
870
846
871
impl PartialOrd < GString > for GStringPtr {
847
872
#[ inline]
848
873
fn partial_cmp ( & self , other : & GString ) -> Option < std:: cmp:: Ordering > {
849
- Some ( self . to_str ( ) . cmp ( other. as_str ( ) ) )
874
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
850
875
}
851
876
}
852
877
@@ -860,7 +885,7 @@ impl PartialOrd<GStringPtr> for str {
860
885
impl PartialOrd < GStringPtr > for GStr {
861
886
#[ inline]
862
887
fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
863
- Some ( self . cmp ( other. to_gstr ( ) ) )
888
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
864
889
}
865
890
}
866
891
@@ -871,10 +896,38 @@ impl PartialOrd<str> for GStringPtr {
871
896
}
872
897
}
873
898
899
+ impl PartialOrd < & str > for GStringPtr {
900
+ #[ inline]
901
+ fn partial_cmp ( & self , other : & & str ) -> Option < std:: cmp:: Ordering > {
902
+ Some ( self . to_str ( ) . cmp ( other) )
903
+ }
904
+ }
905
+
874
906
impl PartialOrd < GStr > for GStringPtr {
875
907
#[ inline]
876
908
fn partial_cmp ( & self , other : & GStr ) -> Option < std:: cmp:: Ordering > {
877
- Some ( self . to_gstr ( ) . cmp ( other) )
909
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
910
+ }
911
+ }
912
+
913
+ impl PartialOrd < & GStr > for GStringPtr {
914
+ #[ inline]
915
+ fn partial_cmp ( & self , other : & & GStr ) -> Option < std:: cmp:: Ordering > {
916
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
917
+ }
918
+ }
919
+
920
+ impl PartialOrd < GStringPtr > for & str {
921
+ #[ inline]
922
+ fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
923
+ Some ( self . cmp ( & other. to_str ( ) ) )
924
+ }
925
+ }
926
+
927
+ impl PartialOrd < GStringPtr > for & GStr {
928
+ #[ inline]
929
+ fn partial_cmp ( & self , other : & GStringPtr ) -> Option < std:: cmp:: Ordering > {
930
+ Some ( unsafe { GStringPtr :: strcmp ( self . as_ptr ( ) , other. as_ptr ( ) ) } )
878
931
}
879
932
}
880
933
0 commit comments