]> git.lizzy.rs Git - rust.git/commitdiff
Change explicit BytesDeref impl into Cloned iterator
authorSimonas Kazlauskas <git@kazlauskas.me>
Mon, 31 Aug 2015 09:53:42 +0000 (12:53 +0300)
committerSimonas Kazlauskas <git@kazlauskas.me>
Mon, 31 Aug 2015 11:48:28 +0000 (14:48 +0300)
src/libcore/str/mod.rs

index 7aeda24a29028d0d858835c3a2472a43f3e36637..757f44acb2f7b8e24c946adbf7ca2c9cdff5db97 100644 (file)
@@ -24,7 +24,7 @@
 use default::Default;
 use fmt;
 use iter::ExactSizeIterator;
-use iter::{Map, Iterator, DoubleEndedIterator};
+use iter::{Map, Cloned, Iterator, DoubleEndedIterator};
 use marker::Sized;
 use mem;
 use ops::{Fn, FnMut, FnOnce};
@@ -369,34 +369,7 @@ pub fn as_str(&self) -> &'a str {
 /// Created with the method `.bytes()`.
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Clone)]
-pub struct Bytes<'a>(Map<slice::Iter<'a, u8>, BytesDeref>);
-
-/// A nameable, clonable fn type
-#[derive(Clone)]
-struct BytesDeref;
-
-impl<'a> Fn<(&'a u8,)> for BytesDeref {
-    #[inline]
-    extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
-        *ptr
-    }
-}
-
-impl<'a> FnMut<(&'a u8,)> for BytesDeref {
-    #[inline]
-    extern "rust-call" fn call_mut(&mut self, (ptr,): (&'a u8,)) -> u8 {
-        Fn::call(&*self, (ptr,))
-    }
-}
-
-impl<'a> FnOnce<(&'a u8,)> for BytesDeref {
-    type Output = u8;
-
-    #[inline]
-    extern "rust-call" fn call_once(self, (ptr,): (&'a u8,)) -> u8 {
-        Fn::call(&self, (ptr,))
-    }
-}
+pub struct Bytes<'a>(Cloned<slice::Iter<'a, u8>>);
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a> Iterator for Bytes<'a> {
@@ -1332,7 +1305,7 @@ fn chars(&self) -> Chars {
 
     #[inline]
     fn bytes(&self) -> Bytes {
-        Bytes(self.as_bytes().iter().map(BytesDeref))
+        Bytes(self.as_bytes().iter().cloned())
     }
 
     #[inline]