diff --git a/src/vec/vec-drain.md b/src/vec/vec-drain.md index fbc8edd0..7a0e7f81 100644 --- a/src/vec/vec-drain.md +++ b/src/vec/vec-drain.md @@ -82,8 +82,10 @@ impl Drop for IntoIter { } } -impl Vec { - pub fn into_iter(self) -> IntoIter { +impl IntoIterator for Vec { + type Item = T; + type IntoIter = IntoIter; + fn into_iter(self) -> IntoIter { unsafe { let iter = RawValIter::new(&self); diff --git a/src/vec/vec-final.md b/src/vec/vec-final.md index 786cfab2..f4cd5977 100644 --- a/src/vec/vec-final.md +++ b/src/vec/vec-final.md @@ -158,19 +158,6 @@ impl Vec { } } - pub fn into_iter(self) -> IntoIter { - unsafe { - let iter = RawValIter::new(&self); - let buf = ptr::read(&self.buf); - mem::forget(self); - - IntoIter { - iter: iter, - _buf: buf, - } - } - } - pub fn drain(&mut self) -> Drain { unsafe { let iter = RawValIter::new(&self); @@ -208,6 +195,23 @@ impl DerefMut for Vec { } } +impl IntoIterator for Vec { + type Item = T; + type IntoIter = IntoIter; + fn into_iter(self) -> IntoIter { + unsafe { + let iter = RawValIter::new(&self); + let buf = ptr::read(&self.buf); + mem::forget(self); + + IntoIter { + iter: iter, + _buf: buf, + } + } + } +} + struct RawValIter { start: *const T, end: *const T, diff --git a/src/vec/vec-into-iter.md b/src/vec/vec-into-iter.md index 33327e8f..dc15c3e6 100644 --- a/src/vec/vec-into-iter.md +++ b/src/vec/vec-into-iter.md @@ -57,8 +57,10 @@ And this is what we end up with for initialization: ```rust,ignore -impl Vec { - pub fn into_iter(self) -> IntoIter { +impl IntoIterator for Vec { + type Item = T; + type IntoIter = IntoIter; + fn into_iter(self) -> IntoIter { // Can't destructure Vec since it's Drop let ptr = self.ptr; let cap = self.cap; diff --git a/src/vec/vec-raw.md b/src/vec/vec-raw.md index a7d8dbe6..e86537b8 100644 --- a/src/vec/vec-raw.md +++ b/src/vec/vec-raw.md @@ -134,8 +134,10 @@ impl Drop for IntoIter { } } -impl Vec { - pub fn into_iter(self) -> IntoIter { +impl IntoIterator for Vec { + type Item = T; + type IntoIter = IntoIter; + fn into_iter(self) -> IntoIter { unsafe { // need to use ptr::read to unsafely move the buf out since it's // not Copy, and Vec implements Drop (so we can't destructure it).