From aa603762ca8d785d5f1f16be710174c237202897 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 8 May 2018 18:56:56 -0700 Subject: [PATCH] refactor(chunk): hide Chunk::into_iter type --- src/chunk.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/chunk.rs b/src/chunk.rs index 92706030..9d2c6125 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -20,6 +20,12 @@ pub struct Chunk { _flow_control: Option, } +// An unexported type to prevent locking `Chunk::into_iter()` to `Bytes::into_iter()`. +#[derive(Debug)] +pub struct IntoIter { + inner: ::IntoIter, +} + struct AutoRelease { cap: usize, release: ReleaseCapacity, @@ -147,11 +153,13 @@ impl Default for Chunk { impl IntoIterator for Chunk { type Item = u8; - type IntoIter = ::IntoIter; + type IntoIter = IntoIter; #[inline] fn into_iter(self) -> Self::IntoIter { - self.bytes.into_iter() + IntoIter { + inner: self.bytes.into_iter(), + } } } @@ -161,3 +169,13 @@ impl Extend for Chunk { self.bytes.extend(iter) } } + +impl Iterator for IntoIter { + type Item = u8; + + #[inline] + fn next(&mut self) -> Option { + self.inner.next() + } +} +