Skip to content

Commit

Permalink
Fix skipped items in extend/from_iter/collect.
Browse files Browse the repository at this point in the history
Fixes #365.
  • Loading branch information
mbrubeck committed Dec 17, 2024
1 parent 21422eb commit 3d64200
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ impl<T, const N: usize> SmallVec<T, N> {
// At this point we either consumed all capacity or the iterator is exhausted (fused)
if let Some(item) = iter.next() {
self.push(item);
len += 1;
} else {
return;
}
Expand Down
9 changes: 9 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,15 @@ fn collect_from_iter() {
let _y: SmallVec<u8, 1> = SmallVec::from_iter(iter);
}

#[test]
fn test_collect_with_spill() {
let input = "0123456";
let collected: SmallVec<char, 4> = input
.chars()
.collect();
assert_eq!(collected, &['0', '1', '2', '3', '4', '5', '6']);
}

#[test]
fn test_spare_capacity_mut() {
let mut v: SmallVec<u8, 2> = SmallVec::new();
Expand Down

0 comments on commit 3d64200

Please sign in to comment.