Skip to content

Commit f54c3db

Browse files
committed
Auto merge of #28119 - nagisa:bytesderef, r=alexcrichton
2 parents 0762f58 + 25dce09 commit f54c3db

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

src/libcore/str/mod.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use convert::AsRef;
2424
use default::Default;
2525
use fmt;
2626
use iter::ExactSizeIterator;
27-
use iter::{Map, Iterator, DoubleEndedIterator};
27+
use iter::{Map, Cloned, Iterator, DoubleEndedIterator};
2828
use marker::Sized;
2929
use mem;
3030
use ops::{Fn, FnMut, FnOnce};
@@ -369,34 +369,7 @@ impl<'a> CharIndices<'a> {
369369
/// Created with the method `.bytes()`.
370370
#[stable(feature = "rust1", since = "1.0.0")]
371371
#[derive(Clone)]
372-
pub struct Bytes<'a>(Map<slice::Iter<'a, u8>, BytesDeref>);
373-
374-
/// A nameable, clonable fn type
375-
#[derive(Clone)]
376-
struct BytesDeref;
377-
378-
impl<'a> Fn<(&'a u8,)> for BytesDeref {
379-
#[inline]
380-
extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
381-
*ptr
382-
}
383-
}
384-
385-
impl<'a> FnMut<(&'a u8,)> for BytesDeref {
386-
#[inline]
387-
extern "rust-call" fn call_mut(&mut self, (ptr,): (&'a u8,)) -> u8 {
388-
Fn::call(&*self, (ptr,))
389-
}
390-
}
391-
392-
impl<'a> FnOnce<(&'a u8,)> for BytesDeref {
393-
type Output = u8;
394-
395-
#[inline]
396-
extern "rust-call" fn call_once(self, (ptr,): (&'a u8,)) -> u8 {
397-
Fn::call(&self, (ptr,))
398-
}
399-
}
372+
pub struct Bytes<'a>(Cloned<slice::Iter<'a, u8>>);
400373

401374
#[stable(feature = "rust1", since = "1.0.0")]
402375
impl<'a> Iterator for Bytes<'a> {
@@ -1347,7 +1320,7 @@ impl StrExt for str {
13471320

13481321
#[inline]
13491322
fn bytes(&self) -> Bytes {
1350-
Bytes(self.as_bytes().iter().map(BytesDeref))
1323+
Bytes(self.as_bytes().iter().cloned())
13511324
}
13521325

13531326
#[inline]

0 commit comments

Comments
 (0)