Skip to content

Commit 94b2383

Browse files
committed
Adds the const_generics feature
1 parent 85440ce commit 94b2383

5 files changed

+539
-352
lines changed

src/into_iter.rs

+31-9
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,39 @@ use crate::Array;
33
use crate::SmallVec;
44
use core::ptr;
55

6+
macro_rules! create_with_parts {
7+
(
8+
<$($({$s_impl_ty_prefix:ident})? $s_impl_ty:ident$(: $s_impl_ty_bound:ident)?),*>,
9+
<$s_decl_ty:ident$(, {$s_decl_const_ty:ident})?>,
10+
$array_item:ty
11+
) => {
12+
613
/// An iterator that consumes a `SmallVec` and yields its items by value.
714
///
815
/// Returned from [`SmallVec::into_iter`][1].
916
///
1017
/// [1]: struct.SmallVec.html#method.into_iter
11-
pub struct IntoIter<A: Array> {
12-
pub(crate) data: SmallVec<A>,
18+
pub struct IntoIter<$($($s_impl_ty_prefix)? $s_impl_ty$(: $s_impl_ty_bound)?),*> {
19+
pub(crate) data: SmallVec<$s_decl_ty$(, {$s_decl_const_ty})?>,
1320
pub(crate) current: usize,
1421
pub(crate) end: usize,
1522
}
1623

17-
impl<A: Array> Drop for IntoIter<A> {
24+
impl<$($($s_impl_ty_prefix)? $s_impl_ty$(: $s_impl_ty_bound)?),*> Drop
25+
for IntoIter<$s_decl_ty$(, {$s_decl_const_ty})?>
26+
{
1827
fn drop(&mut self) {
1928
for _ in self {}
2029
}
2130
}
2231

23-
impl<A: Array> Iterator for IntoIter<A> {
24-
type Item = A::Item;
32+
impl<$($($s_impl_ty_prefix)? $s_impl_ty$(: $s_impl_ty_bound)?),*> Iterator
33+
for IntoIter<$s_decl_ty$(, {$s_decl_const_ty})?>
34+
{
35+
type Item = $array_item;
2536

2637
#[inline]
27-
fn next(&mut self) -> Option<A::Item> {
38+
fn next(&mut self) -> Option<$array_item> {
2839
if self.current == self.end {
2940
None
3041
} else {
@@ -43,9 +54,11 @@ impl<A: Array> Iterator for IntoIter<A> {
4354
}
4455
}
4556

46-
impl<A: Array> DoubleEndedIterator for IntoIter<A> {
57+
impl<$($($s_impl_ty_prefix)? $s_impl_ty$(: $s_impl_ty_bound)?),*> DoubleEndedIterator
58+
for IntoIter<$s_decl_ty$(, {$s_decl_const_ty})?>
59+
{
4760
#[inline]
48-
fn next_back(&mut self) -> Option<A::Item> {
61+
fn next_back(&mut self) -> Option<$array_item> {
4962
if self.current == self.end {
5063
None
5164
} else {
@@ -57,4 +70,13 @@ impl<A: Array> DoubleEndedIterator for IntoIter<A> {
5770
}
5871
}
5972

60-
impl<A: Array> ExactSizeIterator for IntoIter<A> {}
73+
impl<$($($s_impl_ty_prefix)? $s_impl_ty$(: $s_impl_ty_bound)?),*> ExactSizeIterator
74+
for IntoIter<$s_decl_ty$(, {$s_decl_const_ty})?> {}
75+
76+
}
77+
}
78+
79+
#[cfg(feature = "const_generics")]
80+
create_with_parts!(<T, {const} N: usize>, <T, {N}>, T);
81+
#[cfg(not(feature = "const_generics"))]
82+
create_with_parts!(<A: Array>, <A>, A::Item);

0 commit comments

Comments
 (0)