29
29
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
30
30
31
31
use core:: char:: CharExt as C ;
32
- use core:: iter:: FusedIterator ;
32
+ use core:: iter:: { FusedIterator , TrustedLen } ;
33
33
use core:: fmt:: { self , Write } ;
34
34
use tables:: { conversions, derived_property, general_category, property} ;
35
35
@@ -63,11 +63,40 @@ impl Iterator for ToLowercase {
63
63
fn next ( & mut self ) -> Option < char > {
64
64
self . 0 . next ( )
65
65
}
66
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
67
+ self . 0 . size_hint ( )
68
+ }
69
+ fn count ( self ) -> usize {
70
+ self . 0 . count ( )
71
+ }
72
+ fn last ( self ) -> Option < char > {
73
+ self . 0 . last ( )
74
+ }
75
+ }
76
+
77
+ #[ stable( feature = "to_case_extra" , since = "1.17.0" ) ]
78
+ impl DoubleEndedIterator for ToLowercase {
79
+ fn next_back ( & mut self ) -> Option < char > {
80
+ self . 0 . next_back ( )
81
+ }
82
+ }
83
+
84
+ #[ stable( feature = "to_case_extra" , since = "1.17.0" ) ]
85
+ impl ExactSizeIterator for ToLowercase {
86
+ fn len ( & self ) -> usize {
87
+ self . 0 . len ( )
88
+ }
89
+ fn is_empty ( & self ) -> bool {
90
+ self . 0 . is_empty ( )
91
+ }
66
92
}
67
93
68
94
#[ unstable( feature = "fused" , issue = "35602" ) ]
69
95
impl FusedIterator for ToLowercase { }
70
96
97
+ #[ unstable( feature = "trusted_len" , issue = "37572" ) ]
98
+ unsafe impl TrustedLen for ToLowercase { }
99
+
71
100
/// Returns an iterator that yields the uppercase equivalent of a `char`.
72
101
///
73
102
/// This `struct` is created by the [`to_uppercase()`] method on [`char`]. See
@@ -84,11 +113,40 @@ impl Iterator for ToUppercase {
84
113
fn next ( & mut self ) -> Option < char > {
85
114
self . 0 . next ( )
86
115
}
116
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
117
+ self . 0 . size_hint ( )
118
+ }
119
+ fn count ( self ) -> usize {
120
+ self . 0 . count ( )
121
+ }
122
+ fn last ( self ) -> Option < char > {
123
+ self . 0 . last ( )
124
+ }
125
+ }
126
+
127
+ #[ stable( feature = "to_case_extra" , since = "1.17.0" ) ]
128
+ impl DoubleEndedIterator for ToUppercase {
129
+ fn next_back ( & mut self ) -> Option < char > {
130
+ self . 0 . next_back ( )
131
+ }
132
+ }
133
+
134
+ #[ stable( feature = "to_case_extra" , since = "1.17.0" ) ]
135
+ impl ExactSizeIterator for ToUppercase {
136
+ fn len ( & self ) -> usize {
137
+ self . 0 . len ( )
138
+ }
139
+ fn is_empty ( & self ) -> bool {
140
+ self . 0 . is_empty ( )
141
+ }
87
142
}
88
143
89
144
#[ unstable( feature = "fused" , issue = "35602" ) ]
90
145
impl FusedIterator for ToUppercase { }
91
146
147
+ #[ unstable( feature = "trusted_len" , issue = "37572" ) ]
148
+ unsafe impl TrustedLen for ToUppercase { }
149
+
92
150
enum CaseMappingIter {
93
151
Three ( char , char , char ) ,
94
152
Two ( char , char ) ,
@@ -129,6 +187,53 @@ impl Iterator for CaseMappingIter {
129
187
CaseMappingIter :: Zero => None ,
130
188
}
131
189
}
190
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
191
+ ( self . len ( ) , Some ( self . len ( ) ) )
192
+ }
193
+ fn count ( self ) -> usize {
194
+ self . len ( )
195
+ }
196
+ fn last ( mut self ) -> Option < char > {
197
+ self . next_back ( )
198
+ }
199
+ }
200
+
201
+ impl DoubleEndedIterator for CaseMappingIter {
202
+ fn next_back ( & mut self ) -> Option < char > {
203
+ match * self {
204
+ CaseMappingIter :: Three ( a, b, c) => {
205
+ * self = CaseMappingIter :: Two ( a, b) ;
206
+ Some ( c)
207
+ }
208
+ CaseMappingIter :: Two ( a, b) => {
209
+ * self = CaseMappingIter :: One ( a) ;
210
+ Some ( b)
211
+ }
212
+ CaseMappingIter :: One ( a) => {
213
+ * self = CaseMappingIter :: Zero ;
214
+ Some ( a)
215
+ }
216
+ CaseMappingIter :: Zero => None ,
217
+ }
218
+ }
219
+ }
220
+
221
+ impl ExactSizeIterator for CaseMappingIter {
222
+ fn len ( & self ) -> usize {
223
+ match * self {
224
+ CaseMappingIter :: Three ( ..) => 3 ,
225
+ CaseMappingIter :: Two ( ..) => 2 ,
226
+ CaseMappingIter :: One ( ..) => 1 ,
227
+ CaseMappingIter :: Zero => 0 ,
228
+ }
229
+ }
230
+ fn is_empty ( & self ) -> bool {
231
+ if let CaseMappingIter :: Zero = * self {
232
+ true
233
+ } else {
234
+ false
235
+ }
236
+ }
132
237
}
133
238
134
239
#[ stable( feature = "char_struct_display" , since = "1.17.0" ) ]
0 commit comments