2
2
3
3
use std:: { ffi:: c_char, fmt, marker:: PhantomData , mem, ptr} ;
4
4
5
- use crate :: { translate:: * , GStr , GString } ;
6
-
7
- // rustdoc-stripper-ignore-next
8
- /// `NULL`-terminated UTF-8 string as stored in [`StrV`].
9
- ///
10
- /// Unlike [`&GStr`] this does not have its length stored.
11
- #[ repr( transparent) ]
12
- pub struct StrVItem ( ptr:: NonNull < c_char > ) ;
13
-
14
- impl fmt:: Debug for StrVItem {
15
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16
- f. write_str ( self . as_str ( ) )
17
- }
18
- }
19
-
20
- impl std:: ops:: Deref for StrVItem {
21
- type Target = GStr ;
22
-
23
- #[ inline]
24
- fn deref ( & self ) -> & Self :: Target {
25
- self . as_ref ( )
26
- }
27
- }
28
-
29
- impl AsRef < GStr > for StrVItem {
30
- #[ inline]
31
- fn as_ref ( & self ) -> & GStr {
32
- unsafe { GStr :: from_ptr ( self . 0 . as_ptr ( ) ) }
33
- }
34
- }
35
-
36
- impl AsRef < str > for StrVItem {
37
- #[ inline]
38
- fn as_ref ( & self ) -> & str {
39
- self . as_str ( )
40
- }
41
- }
42
-
43
- impl fmt:: Display for StrVItem {
44
- #[ inline]
45
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
46
- f. write_str ( self . as_str ( ) )
47
- }
48
- }
49
-
50
- impl Eq for StrVItem { }
51
-
52
- impl PartialEq for StrVItem {
53
- #[ inline]
54
- fn eq ( & self , other : & StrVItem ) -> bool {
55
- self . as_str ( ) == other. as_str ( )
56
- }
57
- }
58
-
59
- impl PartialEq < StrVItem > for String {
60
- #[ inline]
61
- fn eq ( & self , other : & StrVItem ) -> bool {
62
- self . as_str ( ) == other. as_str ( )
63
- }
64
- }
65
-
66
- impl PartialEq < StrVItem > for GString {
67
- #[ inline]
68
- fn eq ( & self , other : & StrVItem ) -> bool {
69
- self . as_str ( ) == other. as_str ( )
70
- }
71
- }
72
-
73
- impl PartialEq < str > for StrVItem {
74
- #[ inline]
75
- fn eq ( & self , other : & str ) -> bool {
76
- self . as_str ( ) == other
77
- }
78
- }
79
-
80
- impl PartialEq < & str > for StrVItem {
81
- #[ inline]
82
- fn eq ( & self , other : & & str ) -> bool {
83
- self . as_str ( ) == * other
84
- }
85
- }
86
-
87
- impl PartialEq < GStr > for StrVItem {
88
- #[ inline]
89
- fn eq ( & self , other : & GStr ) -> bool {
90
- self . as_str ( ) == other
91
- }
92
- }
93
-
94
- impl PartialEq < & GStr > for StrVItem {
95
- #[ inline]
96
- fn eq ( & self , other : & & GStr ) -> bool {
97
- self . as_str ( ) == * other
98
- }
99
- }
100
-
101
- impl PartialEq < StrVItem > for & str {
102
- #[ inline]
103
- fn eq ( & self , other : & StrVItem ) -> bool {
104
- * self == other. as_str ( )
105
- }
106
- }
107
-
108
- impl PartialEq < StrVItem > for & GStr {
109
- #[ inline]
110
- fn eq ( & self , other : & StrVItem ) -> bool {
111
- * self == other. as_str ( )
112
- }
113
- }
114
-
115
- impl PartialEq < String > for StrVItem {
116
- #[ inline]
117
- fn eq ( & self , other : & String ) -> bool {
118
- self . as_str ( ) == other. as_str ( )
119
- }
120
- }
121
-
122
- impl PartialEq < GString > for StrVItem {
123
- #[ inline]
124
- fn eq ( & self , other : & GString ) -> bool {
125
- self . as_str ( ) == other. as_str ( )
126
- }
127
- }
128
-
129
- impl PartialEq < StrVItem > for str {
130
- #[ inline]
131
- fn eq ( & self , other : & StrVItem ) -> bool {
132
- self == other. as_str ( )
133
- }
134
- }
135
-
136
- impl PartialEq < StrVItem > for GStr {
137
- #[ inline]
138
- fn eq ( & self , other : & StrVItem ) -> bool {
139
- self == other. as_str ( )
140
- }
141
- }
142
-
143
- impl PartialOrd < StrVItem > for StrVItem {
144
- #[ inline]
145
- fn partial_cmp ( & self , other : & StrVItem ) -> Option < std:: cmp:: Ordering > {
146
- Some ( self . as_str ( ) . cmp ( other. as_str ( ) ) )
147
- }
148
- }
149
-
150
- impl Ord for StrVItem {
151
- #[ inline]
152
- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
153
- self . as_str ( ) . cmp ( other. as_str ( ) )
154
- }
155
- }
156
-
157
- impl PartialOrd < StrVItem > for String {
158
- #[ inline]
159
- fn partial_cmp ( & self , other : & StrVItem ) -> Option < std:: cmp:: Ordering > {
160
- Some ( self . as_str ( ) . cmp ( other. as_str ( ) ) )
161
- }
162
- }
163
-
164
- impl PartialOrd < StrVItem > for GString {
165
- #[ inline]
166
- fn partial_cmp ( & self , other : & StrVItem ) -> Option < std:: cmp:: Ordering > {
167
- Some ( self . as_str ( ) . cmp ( other. as_str ( ) ) )
168
- }
169
- }
170
-
171
- impl PartialOrd < String > for StrVItem {
172
- #[ inline]
173
- fn partial_cmp ( & self , other : & String ) -> Option < std:: cmp:: Ordering > {
174
- Some ( self . as_str ( ) . cmp ( other. as_str ( ) ) )
175
- }
176
- }
177
-
178
- impl PartialOrd < GString > for StrVItem {
179
- #[ inline]
180
- fn partial_cmp ( & self , other : & GString ) -> Option < std:: cmp:: Ordering > {
181
- Some ( self . as_str ( ) . cmp ( other. as_str ( ) ) )
182
- }
183
- }
184
-
185
- impl PartialOrd < StrVItem > for str {
186
- #[ inline]
187
- fn partial_cmp ( & self , other : & StrVItem ) -> Option < std:: cmp:: Ordering > {
188
- Some ( self . cmp ( other. as_str ( ) ) )
189
- }
190
- }
191
-
192
- impl PartialOrd < StrVItem > for GStr {
193
- #[ inline]
194
- fn partial_cmp ( & self , other : & StrVItem ) -> Option < std:: cmp:: Ordering > {
195
- Some ( self . as_str ( ) . cmp ( other. as_str ( ) ) )
196
- }
197
- }
198
-
199
- impl PartialOrd < str > for StrVItem {
200
- #[ inline]
201
- fn partial_cmp ( & self , other : & str ) -> Option < std:: cmp:: Ordering > {
202
- Some ( self . as_str ( ) . cmp ( other) )
203
- }
204
- }
205
-
206
- impl PartialOrd < GStr > for StrVItem {
207
- #[ inline]
208
- fn partial_cmp ( & self , other : & GStr ) -> Option < std:: cmp:: Ordering > {
209
- Some ( self . as_str ( ) . cmp ( other) )
210
- }
211
- }
212
-
213
- impl AsRef < StrVItem > for StrVItem {
214
- #[ inline]
215
- fn as_ref ( & self ) -> & StrVItem {
216
- self
217
- }
218
- }
219
-
220
- impl AsRef < std:: ffi:: OsStr > for StrVItem {
221
- #[ inline]
222
- fn as_ref ( & self ) -> & std:: ffi:: OsStr {
223
- self . as_str ( ) . as_ref ( )
224
- }
225
- }
226
-
227
- impl AsRef < std:: path:: Path > for StrVItem {
228
- #[ inline]
229
- fn as_ref ( & self ) -> & std:: path:: Path {
230
- self . as_str ( ) . as_ref ( )
231
- }
232
- }
233
-
234
- impl AsRef < [ u8 ] > for StrVItem {
235
- #[ inline]
236
- fn as_ref ( & self ) -> & [ u8 ] {
237
- self . as_bytes ( )
238
- }
239
- }
240
-
241
- impl std:: hash:: Hash for StrVItem {
242
- #[ inline]
243
- fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
244
- self . as_str ( ) . hash ( state) ;
245
- }
246
- }
5
+ use crate :: { translate:: * , GStr , GStrPtr , GString } ;
247
6
248
7
// rustdoc-stripper-ignore-next
249
8
/// Minimum size of the `StrV` allocation.
@@ -341,25 +100,25 @@ impl Default for StrV {
341
100
}
342
101
}
343
102
344
- impl AsRef < [ StrVItem ] > for StrV {
103
+ impl AsRef < [ GStrPtr ] > for StrV {
345
104
#[ inline]
346
- fn as_ref ( & self ) -> & [ StrVItem ] {
105
+ fn as_ref ( & self ) -> & [ GStrPtr ] {
347
106
self . as_slice ( )
348
107
}
349
108
}
350
109
351
- impl std:: borrow:: Borrow < [ StrVItem ] > for StrV {
110
+ impl std:: borrow:: Borrow < [ GStrPtr ] > for StrV {
352
111
#[ inline]
353
- fn borrow ( & self ) -> & [ StrVItem ] {
112
+ fn borrow ( & self ) -> & [ GStrPtr ] {
354
113
self . as_slice ( )
355
114
}
356
115
}
357
116
358
117
impl std:: ops:: Deref for StrV {
359
- type Target = [ StrVItem ] ;
118
+ type Target = [ GStrPtr ] ;
360
119
361
120
#[ inline]
362
- fn deref ( & self ) -> & [ StrVItem ] {
121
+ fn deref ( & self ) -> & [ GStrPtr ] {
363
122
self . as_slice ( )
364
123
}
365
124
}
@@ -401,8 +160,8 @@ impl std::iter::FromIterator<GString> for StrV {
401
160
}
402
161
403
162
impl < ' a > std:: iter:: IntoIterator for & ' a StrV {
404
- type Item = & ' a StrVItem ;
405
- type IntoIter = std:: slice:: Iter < ' a , StrVItem > ;
163
+ type Item = & ' a GStrPtr ;
164
+ type IntoIter = std:: slice:: Iter < ' a , GStrPtr > ;
406
165
407
166
#[ inline]
408
167
fn into_iter ( self ) -> Self :: IntoIter {
@@ -442,12 +201,12 @@ impl IntoIter {
442
201
// rustdoc-stripper-ignore-next
443
202
/// Returns the remaining items as slice.
444
203
#[ inline]
445
- pub fn as_slice ( & self ) -> & [ StrVItem ] {
204
+ pub fn as_slice ( & self ) -> & [ GStrPtr ] {
446
205
unsafe {
447
206
if self . len == 0 {
448
207
& [ ]
449
208
} else {
450
- std:: slice:: from_raw_parts ( self . idx . as_ptr ( ) as * const StrVItem , self . len )
209
+ std:: slice:: from_raw_parts ( self . idx . as_ptr ( ) as * const GStrPtr , self . len )
451
210
}
452
211
}
453
212
}
@@ -648,7 +407,7 @@ impl StrV {
648
407
// rustdoc-stripper-ignore-next
649
408
/// Borrows a C array.
650
409
#[ inline]
651
- pub unsafe fn from_glib_borrow < ' a > ( ptr : * const * const c_char ) -> & ' a [ StrVItem ] {
410
+ pub unsafe fn from_glib_borrow < ' a > ( ptr : * const * const c_char ) -> & ' a [ GStrPtr ] {
652
411
let mut len = 0 ;
653
412
if !ptr. is_null ( ) {
654
413
while !( * ptr. add ( len) ) . is_null ( ) {
@@ -661,16 +420,13 @@ impl StrV {
661
420
// rustdoc-stripper-ignore-next
662
421
/// Borrows a C array.
663
422
#[ inline]
664
- pub unsafe fn from_glib_borrow_num < ' a > (
665
- ptr : * const * const c_char ,
666
- len : usize ,
667
- ) -> & ' a [ StrVItem ] {
423
+ pub unsafe fn from_glib_borrow_num < ' a > ( ptr : * const * const c_char , len : usize ) -> & ' a [ GStrPtr ] {
668
424
debug_assert ! ( !ptr. is_null( ) || len == 0 ) ;
669
425
670
426
if len == 0 {
671
427
& [ ]
672
428
} else {
673
- std:: slice:: from_raw_parts ( ptr as * const StrVItem , len)
429
+ std:: slice:: from_raw_parts ( ptr as * const GStrPtr , len)
674
430
}
675
431
}
676
432
@@ -919,14 +675,14 @@ impl StrV {
919
675
}
920
676
921
677
// rustdoc-stripper-ignore-next
922
- /// Borrows this slice as a `&[StrVItem ]`.
678
+ /// Borrows this slice as a `&[GStrPtr ]`.
923
679
#[ inline]
924
- pub fn as_slice ( & self ) -> & [ StrVItem ] {
680
+ pub fn as_slice ( & self ) -> & [ GStrPtr ] {
925
681
unsafe {
926
682
if self . len == 0 {
927
683
& [ ]
928
684
} else {
929
- std:: slice:: from_raw_parts ( self . ptr . as_ptr ( ) as * const StrVItem , self . len )
685
+ std:: slice:: from_raw_parts ( self . ptr . as_ptr ( ) as * const GStrPtr , self . len )
930
686
}
931
687
}
932
688
}
@@ -1192,7 +948,7 @@ impl crate::StaticType for StrV {
1192
948
}
1193
949
}
1194
950
1195
- impl < ' a > crate :: StaticType for & ' a [ StrVItem ] {
951
+ impl < ' a > crate :: StaticType for & ' a [ GStrPtr ] {
1196
952
#[ inline]
1197
953
fn static_type ( ) -> crate :: Type {
1198
954
<Vec < String > >:: static_type ( )
@@ -1212,7 +968,7 @@ unsafe impl<'a> crate::value::FromValue<'a> for StrV {
1212
968
}
1213
969
}
1214
970
1215
- unsafe impl < ' a > crate :: value:: FromValue < ' a > for & ' a [ StrVItem ] {
971
+ unsafe impl < ' a > crate :: value:: FromValue < ' a > for & ' a [ GStrPtr ] {
1216
972
type Checker = crate :: value:: GenericValueTypeChecker < Self > ;
1217
973
1218
974
unsafe fn from_value ( value : & ' a crate :: value:: Value ) -> Self {
0 commit comments