@@ -21,6 +21,7 @@ pub use self::Searcher::{Naive, TwoWay, TwoWayLong};
21
21
22
22
use char:: Char ;
23
23
use char;
24
+ use clone:: Clone ;
24
25
use cmp:: { Eq , mod} ;
25
26
use default:: Default ;
26
27
use iter:: { Map , Iterator , IteratorExt , DoubleEndedIterator } ;
@@ -31,7 +32,7 @@ use mem;
31
32
use num:: Int ;
32
33
use option:: Option ;
33
34
use option:: Option :: { None , Some } ;
34
- use ops:: FnMut ;
35
+ use ops:: { Fn , FnMut } ;
35
36
use ptr:: RawPtr ;
36
37
use raw:: { Repr , Slice } ;
37
38
use slice:: { mod, SliceExt } ;
@@ -316,7 +317,23 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharOffsets<'a> {
316
317
317
318
/// External iterator for a string's bytes.
318
319
/// Use with the `std::iter` module.
319
- pub type Bytes < ' a > = Map < & ' a u8 , u8 , slice:: Items < ' a , u8 > , fn ( & u8 ) -> u8 > ;
320
+ pub type Bytes < ' a > = Map < & ' a u8 , u8 , slice:: Items < ' a , u8 > , BytesFn > ;
321
+
322
+ /// A temporary new type wrapper that ensures that the `Bytes` iterator
323
+ /// is cloneable.
324
+ #[ deriving( Copy ) ]
325
+ #[ experimental = "iterator type instability" ]
326
+ pub struct BytesFn ( fn ( & u8 ) -> u8 ) ;
327
+
328
+ impl < ' a > Fn ( & ' a u8 ) -> u8 for BytesFn {
329
+ extern "rust-call" fn call ( & self , ( ptr, ) : ( & ' a u8 , ) ) -> u8 {
330
+ ( self . 0 ) ( ptr)
331
+ }
332
+ }
333
+
334
+ impl Clone for BytesFn {
335
+ fn clone ( & self ) -> BytesFn { * self }
336
+ }
320
337
321
338
/// An iterator over the substrings of a string, separated by `sep`.
322
339
#[ deriving( Clone ) ]
@@ -2009,7 +2026,7 @@ impl StrPrelude for str {
2009
2026
fn bytes ( & self ) -> Bytes {
2010
2027
fn deref ( & x: & u8 ) -> u8 { x }
2011
2028
2012
- self . as_bytes ( ) . iter ( ) . map ( deref)
2029
+ self . as_bytes ( ) . iter ( ) . map ( BytesFn ( deref) )
2013
2030
}
2014
2031
2015
2032
#[ inline]
0 commit comments