@@ -21,6 +21,7 @@ pub use self::Searcher::{Naive, TwoWay, TwoWayLong};
2121
2222use char:: Char ;
2323use char;
24+ use clone:: Clone ;
2425use cmp:: { Eq , mod} ;
2526use default:: Default ;
2627use iter:: { Map , Iterator , IteratorExt , DoubleEndedIterator } ;
@@ -31,7 +32,7 @@ use mem;
3132use num:: Int ;
3233use option:: Option ;
3334use option:: Option :: { None , Some } ;
34- use ops:: FnMut ;
35+ use ops:: { Fn , FnMut } ;
3536use ptr:: RawPtr ;
3637use raw:: { Repr , Slice } ;
3738use slice:: { mod, SliceExt } ;
@@ -316,7 +317,23 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharOffsets<'a> {
316317
317318/// External iterator for a string's bytes.
318319/// 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+ }
320337
321338/// An iterator over the substrings of a string, separated by `sep`.
322339#[ deriving( Clone ) ]
@@ -2009,7 +2026,7 @@ impl StrPrelude for str {
20092026 fn bytes ( & self ) -> Bytes {
20102027 fn deref ( & x: & u8 ) -> u8 { x }
20112028
2012- self . as_bytes ( ) . iter ( ) . map ( deref)
2029+ self . as_bytes ( ) . iter ( ) . map ( BytesFn ( deref) )
20132030 }
20142031
20152032 #[ inline]
0 commit comments