Make update of major heapless version a possibly non breaking change

This commit is contained in:
Sosthène Guédon
2024-06-19 16:36:17 +02:00
committed by sosthene-nitrokey
parent 413930ea2a
commit b7ef67366c
2 changed files with 23 additions and 3 deletions
+3
View File
@@ -17,3 +17,6 @@ serde = { version = "1.0", default-features = false }
[dev-dependencies]
serde_test = "1.0.176"
[features]
default = []
+20 -3
View File
@@ -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<const N: usize> TryFrom<&[u8]> for Bytes<N> {
impl<const N: usize> Bytes<N> {
/// Construct a new, empty `Bytes<N>`.
pub fn new() -> Self {
Bytes::from(Vec::new())
Self { bytes: Vec::new() }
}
pub fn as_ptr(&self) -> *const u8 {
@@ -526,12 +529,26 @@ impl<const N: usize> Hash for Bytes<N> {
}
}
#[derive(Clone)]
pub struct IntoIter<const N: usize> {
inner: <Vec<u8, N> as IntoIterator>::IntoIter,
}
impl<const N: usize> Iterator for IntoIter<N> {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
self.inner.next()
}
}
impl<const N: usize> IntoIterator for Bytes<N> {
type Item = u8;
type IntoIter = <Vec<u8, N> as IntoIterator>::IntoIter;
type IntoIter = IntoIter<N>;
fn into_iter(self) -> Self::IntoIter {
self.bytes.into_iter()
IntoIter {
inner: self.bytes.into_iter(),
}
}
}