@@ -26,8 +26,9 @@ use core::str::Split;
26
26
/// [`split_whitespace`]: ../../std/primitive.str.html#method.split_whitespace
27
27
/// [`str`]: ../../std/primitive.str.html
28
28
#[ stable( feature = "split_whitespace" , since = "1.1.0" ) ]
29
+ #[ derive( Clone ) ]
29
30
pub struct SplitWhitespace < ' a > {
30
- inner : Filter < Split < ' a , fn ( char ) -> bool > , fn ( & & str ) -> bool > ,
31
+ inner : Filter < Split < ' a , IsWhitespace > , IsNotEmpty > ,
31
32
}
32
33
33
34
/// Methods for Unicode string slices
@@ -44,17 +45,7 @@ pub trait UnicodeStr {
44
45
impl UnicodeStr for str {
45
46
#[ inline]
46
47
fn split_whitespace ( & self ) -> SplitWhitespace {
47
- fn is_not_empty ( s : & & str ) -> bool {
48
- !s. is_empty ( )
49
- }
50
- let is_not_empty: fn ( & & str ) -> bool = is_not_empty; // coerce to fn pointer
51
-
52
- fn is_whitespace ( c : char ) -> bool {
53
- c. is_whitespace ( )
54
- }
55
- let is_whitespace: fn ( char ) -> bool = is_whitespace; // coerce to fn pointer
56
-
57
- SplitWhitespace { inner : self . split ( is_whitespace) . filter ( is_not_empty) }
48
+ SplitWhitespace { inner : self . split ( IsWhitespace ) . filter ( IsNotEmpty ) }
58
49
}
59
50
60
51
#[ inline]
@@ -139,6 +130,45 @@ impl<I> Iterator for Utf16Encoder<I>
139
130
impl < I > FusedIterator for Utf16Encoder < I >
140
131
where I : FusedIterator < Item = char > { }
141
132
133
+ #[ derive( Clone ) ]
134
+ struct IsWhitespace ;
135
+
136
+ impl FnOnce < ( char , ) > for IsWhitespace {
137
+ type Output = bool ;
138
+
139
+ #[ inline]
140
+ extern "rust-call" fn call_once ( mut self , arg : ( char , ) ) -> bool {
141
+ self . call_mut ( arg)
142
+ }
143
+ }
144
+
145
+ impl FnMut < ( char , ) > for IsWhitespace {
146
+ #[ inline]
147
+ extern "rust-call" fn call_mut ( & mut self , arg : ( char , ) ) -> bool {
148
+ arg. 0 . is_whitespace ( )
149
+ }
150
+ }
151
+
152
+ #[ derive( Clone ) ]
153
+ struct IsNotEmpty ;
154
+
155
+ impl < ' a , ' b > FnOnce < ( & ' a & ' b str , ) > for IsNotEmpty {
156
+ type Output = bool ;
157
+
158
+ #[ inline]
159
+ extern "rust-call" fn call_once ( mut self , arg : ( & & str , ) ) -> bool {
160
+ self . call_mut ( arg)
161
+ }
162
+ }
163
+
164
+ impl < ' a , ' b > FnMut < ( & ' a & ' b str , ) > for IsNotEmpty {
165
+ #[ inline]
166
+ extern "rust-call" fn call_mut ( & mut self , arg : ( & & str , ) ) -> bool {
167
+ !arg. 0 . is_empty ( )
168
+ }
169
+ }
170
+
171
+
142
172
#[ stable( feature = "split_whitespace" , since = "1.1.0" ) ]
143
173
impl < ' a > Iterator for SplitWhitespace < ' a > {
144
174
type Item = & ' a str ;
0 commit comments