@@ -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,41 @@ 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
+ extern "rust-call" fn call_once ( mut self , arg : ( char , ) ) -> bool {
140
+ self . call_mut ( arg)
141
+ }
142
+ }
143
+
144
+ impl FnMut < ( char , ) > for IsWhitespace {
145
+ extern "rust-call" fn call_mut ( & mut self , arg : ( char , ) ) -> bool {
146
+ arg. 0 . is_whitespace ( )
147
+ }
148
+ }
149
+
150
+ #[ derive( Clone ) ]
151
+ struct IsNotEmpty ;
152
+
153
+ impl < ' a , ' b > FnOnce < ( & ' a & ' b str , ) > for IsNotEmpty {
154
+ type Output = bool ;
155
+
156
+ extern "rust-call" fn call_once ( mut self , arg : ( & & str , ) ) -> bool {
157
+ self . call_mut ( arg)
158
+ }
159
+ }
160
+
161
+ impl < ' a , ' b > FnMut < ( & ' a & ' b str , ) > for IsNotEmpty {
162
+ extern "rust-call" fn call_mut ( & mut self , arg : ( & & str , ) ) -> bool {
163
+ !arg. 0 . is_empty ( )
164
+ }
165
+ }
166
+
167
+
142
168
#[ stable( feature = "split_whitespace" , since = "1.1.0" ) ]
143
169
impl < ' a > Iterator for SplitWhitespace < ' a > {
144
170
type Item = & ' a str ;
0 commit comments