about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-09-04 12:34:03 +0000
committerbors <bors@rust-lang.org>2015-09-04 12:34:03 +0000
commit94ddfc77072d99b16a5cc779d2b1f8d69e0d6850 (patch)
treeaffabf7c7026bbb0bf1c0cb2b453dd75bea590d5 /src/libcore
parent6f1014f3510f3c5cc2b524aa4cb18bf91c3fd50f (diff)
parent25dce09a962fb378ab3ecc142f873255c247788a (diff)
downloadrust-94ddfc77072d99b16a5cc779d2b1f8d69e0d6850.tar.gz
rust-94ddfc77072d99b16a5cc779d2b1f8d69e0d6850.zip
Auto merge of #28119 - nagisa:bytesderef, r=alexcrichton
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/str/mod.rs33
1 files changed, 3 insertions, 30 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index 4664162358d..79718ad6d77 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -24,7 +24,7 @@ use convert::AsRef;
 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 @@ impl<'a> CharIndices<'a> {
 /// 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> {
@@ -1352,7 +1325,7 @@ impl StrExt for str {
 
     #[inline]
     fn bytes(&self) -> Bytes {
-        Bytes(self.as_bytes().iter().map(BytesDeref))
+        Bytes(self.as_bytes().iter().cloned())
     }
 
     #[inline]