diff --git a/Cargo.toml b/Cargo.toml index a2e32e7..3ffc6f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,6 @@ serde = { version = "1.0", default-features = false } [dev-dependencies] serde_test = "1.0.176" + +[features] +default = [] diff --git a/src/lib.rs b/src/lib.rs index 88d62a3..6c9f5fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,9 @@ #![cfg_attr(not(test), no_std)] #![allow(clippy::result_unit_err)] +#[cfg(not(feature = "default"))] +compile_error!("default features are required so that functionality can be put behind a feature flag in the future"); + use core::{ cmp::Ordering, fmt::{self, Debug}, @@ -53,7 +56,7 @@ impl TryFrom<&[u8]> for Bytes { impl Bytes { /// Construct a new, empty `Bytes`. pub fn new() -> Self { - Bytes::from(Vec::new()) + Self { bytes: Vec::new() } } pub fn as_ptr(&self) -> *const u8 { @@ -526,12 +529,26 @@ impl Hash for Bytes { } } +#[derive(Clone)] +pub struct IntoIter { + inner: as IntoIterator>::IntoIter, +} + +impl Iterator for IntoIter { + type Item = u8; + fn next(&mut self) -> Option { + self.inner.next() + } +} + impl IntoIterator for Bytes { type Item = u8; - type IntoIter = as IntoIterator>::IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> Self::IntoIter { - self.bytes.into_iter() + IntoIter { + inner: self.bytes.into_iter(), + } } }